wenbao与合肥网络赛

 

啦啦啦。。。只是签到题而已

 

异或密码

http://acm.hdu.edu.cn/showproblem.php?pid=5968

 

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 using namespace std;
 5 int n, t, m, a[105], b[2050], x;
 6 void lala(){
 7     for(int i = 2; i <= n; i++){
 8         int sum = 0;
 9         for(int j = 0; j < n; j++){
10             if(j < i-1){
11                 sum ^= a[j];
12             }else if(j == i-1){
13                 sum ^= a[j];
14                 b[sum] = i;
15             }else{
16                 sum = sum ^a[j-i]^a[j];
17                 b[sum] = i;
18             }
19         }
20     }
21 }
22 int main(){
23     scanf("%d", &t);
24     while(t--){
25         scanf("%d", &n);
26         for(int i = 0; i < n; i++){
27             scanf("%d", &a[i]);
28             b[a[i]] = 1;
29         }
30         lala();
31         scanf("%d", &m);
32         for(int j = 0; j < m; j++){
33             scanf("%d", &x);
34             for(int i = 0; ; i++){
35                 if(x+i < 2050 && b[x+i] && x-i >= 0 && b[x-i]) {
36                     printf("%d\n", max(b[x+i], b[x-i]));
37                     break;
38                 }
39                 if(x+i < 2050 && b[x+i]){
40                     printf("%d\n", b[x+i]);
41                     break;
42                 }
43                 if(x-i >= 0 && b[x-i]){
44                     printf("%d\n", b[x-i]);
45                     break;
46                 }
47             }
48         }
49         printf("\n");
50         memset(b, 0, sizeof(b));
51     }
52     return 0;
53 }

 

 

最大位或

http://acm.hdu.edu.cn/showproblem.php?pid=5969

 1 #include <iostream>
 2 #include <string.h>
 3 #include <cmath>
 4 #include <stdio.h>
 5 using namespace std;
 6 #define ll long long
 7 int n, flag;
 8 ll l, r, sum;
 9 int a[66], b[66];
10 int main(){
11     scanf("%d", &n);
12     while(n--){
13         scanf("%lld %lld", &l, &r);
14         if(l == r) printf("%lld\n", l);
15         else{
16             memset(a, 0, sizeof(a));
17             memset(b, 0, sizeof(b));
18             int i = 0, j = 0;
19             sum = 0;
20             while(l){
21                 a[i] = l%2, i++;
22                 l >>= 1;
23             }
24             while(r){
25                 b[j] = r%2, j++;
26                 r >>= 1;
27             }
28             int len = max(i, j);
29             for(int k = len - 1; k >= 0; k--){
30                 if(a[k] == b[k]){
31                     if(a[k] == 1){
32                         sum += (ll)pow(2.0, k);
33                     }
34                 }else{
35                     sum += (ll)pow(2.0, k+1) -1;
36                     break;
37                 }
38             }
39             printf("%lld\n", sum);
40         }
41     }
42     return 0;
43 }

 

 

 

 

只有不断学习才能进步!

 

posted @ 2018-04-14 13:47  wenbao  阅读(101)  评论(0编辑  收藏  举报