02训练赛

    科技2022-08-23  105

    ZOJ 3870

    分析:可以发现,将序列从小到大排序后,通过观察二进制可以发现,只要当前对应的二进制位 上为0,只要前面的数对应的最高位为1,则异或成功....比如: 1 0001 2 0010 3 0011 4 0100 5 0101 从右往左:2 的第一位为0,对应比他小的数(1)的最高位为1,异或成功,同理,一直遍历下去 3 的每一位都异或失败 4 的第一位与前面的数 1 异或成功,第二位与前面的 23 都异或成功 ... #include <set> #include <map> #include <cmath> #include <stack> #include <queue> #include <string> #include <vector> #include<cstring> #include <stdio.h> #include <iostream> #include <algorithm> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; const int maxn=1e5+5; int t,n,m,a[maxn]; int main() { scanf("%d",&t); while (t--){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); int ans=0,cnt[50]={0}; for(int i=1;i<=n;i++){ int tot=0; while (a[i]){ tot++; int k=a[i]&1; if(k==0) ans+=cnt[tot]; a[i]>>=1; } cnt[tot]++; } printf("%d\n",ans); } return 0; }

    ZOJ 3878 模拟:

    #include <set> #include <map> #include <cmath> #include <stack> #include <queue> #include <string> #include <vector> #include<cstring> #include <stdio.h> #include <iostream> #include <algorithm> #define INF 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; const int maxn=1e5+5; int t,n,m; string s; int main() { while (getline(cin,s)) { int len = s.length(); for (int i = 0; i < len; i++) { if (s[i] == '-') s[i] = '['; else if (s[i] == '_') s[i] = '{'; else if (s[i] == '=') s[i] = ']'; else if (s[i] == '+') s[i] = '}'; else if (s[i] == 'q') s[i] = '\''; else if (s[i] == 'Q') s[i] = '"'; else if (s[i] == 'w') s[i] = ','; else if (s[i] == 'W') s[i] = '<'; else if (s[i] == 'e') s[i] = '.'; else if (s[i] == 'E') s[i] = '>'; else if (s[i] == 'R') s[i] = 'P'; else if (s[i] == 'r') s[i] = 'p'; else if (s[i] == 'T') s[i] = 'Y'; else if (s[i] == 't') s[i] = 'y'; else if (s[i] == 'Y') s[i] = 'F'; else if (s[i] == 'y') s[i] = 'f'; else if (s[i] == 'U') s[i] = 'G'; else if (s[i] == 'u') s[i] = 'g'; else if (s[i] == 'I') s[i] = 'C'; else if (s[i] == 'i') s[i] = 'c'; else if (s[i] == 'O') s[i] = 'R'; else if (s[i] == 'o') s[i] = 'r'; else if (s[i] == 'P') s[i] = 'L'; else if (s[i] == 'p') s[i] = 'l'; else if (s[i] == '[') s[i] = '/'; else if (s[i] == '{') s[i] = '?'; else if (s[i] == ']') s[i] = '='; else if (s[i] == '}') s[i] = '+'; else if (s[i] == 's') s[i] = 'o'; else if (s[i] == 'S') s[i] = 'O'; else if (s[i] == 'D') s[i] = 'E'; else if (s[i] == 'd') s[i] = 'e'; else if (s[i] == 'F') s[i] = 'U'; else if (s[i] == 'f') s[i] = 'u'; else if (s[i] == 'G') s[i] = 'I'; else if (s[i] == 'g') s[i] = 'i'; else if (s[i] == 'h') s[i] = 'd'; else if (s[i] == 'H') s[i] = 'D'; else if (s[i] == 'J') s[i] = 'H'; else if (s[i] == 'j') s[i] = 'h'; else if (s[i] == 'K') s[i] = 'T'; else if (s[i] == 'k') s[i] = 't'; else if (s[i] == 'L') s[i] = 'N'; else if (s[i] == 'l') s[i] = 'n'; else if (s[i] == ':') s[i] = 'S';// else if (s[i] == ';') s[i] = 's';// else if (s[i] == '\'') s[i] = '-'; else if (s[i] == '"') s[i] = '_'; else if (s[i] == 'Z') s[i] = ':'; else if (s[i] == 'z') s[i] = ';';// else if (s[i] == 'X') s[i] = 'Q'; else if (s[i] == 'x') s[i] = 'q'; else if (s[i] == 'C') s[i] = 'J'; else if (s[i] == 'c') s[i] = 'j'; else if (s[i] == 'V') s[i] = 'K'; else if (s[i] == 'v') s[i] = 'k'; else if (s[i] == 'B') s[i] = 'X'; else if (s[i] == 'b') s[i] = 'x'; else if (s[i] == 'N') s[i] = 'B'; else if (s[i] == 'n') s[i] = 'b'; else if (s[i] == '<') s[i] = 'W'; else if (s[i] == ',') s[i] = 'w'; else if (s[i] == '>') s[i] = 'V'; else if (s[i] == '.') s[i] = 'v'; else if (s[i] == '/') s[i] = 'z'; else if (s[i] == '?') s[i] = 'Z'; } cout<<s<<endl; } return 0; }
    Processed: 0.012, SQL: 9