第三次月赛题解

1000

每天只要复习收益最大的那门课即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef long long LL;                   
16 const int INF = 1<<30;
17 /*
18 */
19 const int N = 100 + 10;
20 int dp[N][N];
21 int a[N][N];
22 char in[] = "D:\\3\\1004\\0.in";
23 char out[] = "D:\\3\\1004\\0.out";
24 char str[] = "0123456789";
25 int main()
26 {
27     //for (int z = 0; z <= 9; ++z)
28     {
29         //in[10] = str[z];
30         //out[10] = str[z];
31         //freopen(in, "r", stdin);
32         //freopen(out, "w", stdout);
33         int n, m;
34         while (scanf("%d%d", &n, &m) != EOF)
35         {
36             for (int i = 1; i <= n; ++i)
37             {
38                 for (int j = 1; j <= m; ++j)
39                     scanf("%1d", &a[i][j]);
40             }
41 
42             int ans = 0;
43             for (int i = 1; i <= n; ++i)
44             {
45                 sort(a[i] + 1, a[i] + n + 1);
46                 ans += a[i][n];
47             }
48             printf("%d\n", ans);
49         }
50     }
51     return 0;
52 }
View Code

 

1001

个位数的位数是1,十位的是2, 所以只要算出个位数的个数*1,加上十位数的个数*2,加....

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef __int64 LL;
16 const int INF = 1 << 30;
17 /*
18 
19 */
20 char in[] = "D:\\3\\1000\\0.in";
21 char out[] = "D:\\3\\1000\\0.out";
22 char str[] = "0123456789";
23 int main()
24 {
25     //for (int z = 0; z <= 9; ++z)
26     {
27         //in[10] = str[z];
28         //out[10] = str[z];
29         //freopen(in, "r", stdin);
30         //freopen(out, "w", stdout);
31         LL n;
32         while (scanf("%I64d", &n) != EOF)
33         {
34             char str[11];
35             LL m = 1;
36             sprintf(str, "%I64d", n);
37             LL len = strlen(str);
38             LL ans = 0;
39             LL t = 9;
40             LL i = 0;
41             for (i = 0; i < len - 1; ++i)
42             {
43                 ans = ans + t * (i + 1);
44                 t *= 10;//位数为i+1的数字有多少个
45                 m = m * 10;
46             }
47             ans += (i + 1) * (n - m + 1);
48             printf("%I64d\n", ans);
49             //puts("8888888899");
50         }
51     }
52 
53     return 0;
54 }
View Code

 

1002

ABC三根柱子

设T(n)是将n个盘子借助一根柱子移到另一个柱子上去所要移动的最小次数, 那么要先将n-1个盘子移到B柱子上去,需要T(n-1)次,然后将第n个盘子移到C柱子上去,需要一次,然后将n-1个盘子移动C柱子上去

需要T(n-1)次, 所以T(n) = 2*T(n-1) + 1

设T(n)+1 = 2( T(n-1)+1 )  = 2 * 2( T(n-2)+1) = ... = 2^n    所以T(n) = 2^n - 1

需要注意的是2^64 会爆

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef unsigned __int64 LL;                   
16 const int INF = 1<<30;
17 /*
18 
19 */
20 char str[] = "0123456789";
21 char addressIn[] = "D:\\3\\1001\\1.in";
22 char addressOut[] = "D:\\3\\1001\\1.out";
23 int main()
24 {
25     int n;
26     LL ans;
27     //for (int i = 0; i < 9; ++i)
28     {
29         //addressIn[10] = str[i];
30         //addressOut[10] = str[i];
31         
32         //freopen(addressIn, "r", stdin);
33         //freopen(addressOut, "w", stdout);
34         while (scanf("%d", &n) != EOF)
35         {
36             ans = 0;
37             if (n == 0)
38             {
39                 puts("0");
40                 continue;
41             }
42             else if (n == 64)
43                 ans = 0;
44             else
45             {
46                 ans = 1;
47                 ans <<= n;
48             }
49             ans -= 1;
50             printf("%I64u\n", ans);
51         }
52     }
53     return 0;
54 }
View Code

 

1003

根据异或的性质,  a^a = 0      a^a^a = a ,  所以将n个数字进行异或, 如果结果是0,说明所有的数字都出现了偶数次, 如果结果不为0,那么就输出

需要注意的是,如果a为0,切出现了奇数次, 其异或结果也是0 ,  所以异或时将每个数字加1即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 #include<time.h>
14 using namespace std;
15 #pragma warning(disable:4996)
16 typedef long long LL;                   
17 const int INF = 1<<30;
18 /*
19 
20 */
21 __int64 input()
22 {
23     char ch = getchar();
24     while (ch<'0' || ch>'9')
25         ch = getchar();
26     __int64 x = 0;
27     while (ch >= '0' && ch <= '9')
28     {
29         x = x * 10 + ch - '0';
30         ch = getchar();
31     }
32     return x;
33 }
34 const LL MAX = 1152921504606846976LL;
35 LL a[5000000+10];
36 char in[] = "D:\\3\\1002\\0.in";
37 char out[] = "D:\\3\\1002\\0.out";
38 char str[] = "0123456789";
39 int main()
40 {
41     int n;
42     //for (int k = 0; k <= 9; ++k)
43     {
44         //in[10] = str[k];
45         //freopen(in, "r", stdin);
46         //freopen("D:\\3\\1002\\0.out", "w", stdout);
47 
48         while (scanf("%d",&n)!=EOF)
49         {
50             LL ans = 0, x;
51             for (int i = 0; i < n; ++i)
52             {
53                 //scanf("%I64d", &a[i]);
54                 //input(a[i]);
55                 a[i] = input();
56                 a[i]++;
57                 ans ^= a[i];
58             }
59             //sort(a, a + n);
60             printf("%I64d\n", ans==0?-1:ans-1);
61         }
62     }
63     return 0;
64 }
View Code

 

1004

这个问题难点是不知道要打扫哪几列, 其实只要我们枚举每一行,使得这一行全为1, 那么就知道了要打扫哪几列,  然后判断剩下的n-1行,看打扫了这几列之后是否全为1

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <iostream>
 6 #include <queue>
 7 #include <stack>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <string>
12 #include <math.h>
13 using namespace std;
14 #pragma warning(disable:4996)
15 typedef long long LL;
16 const int INF = 1 << 30;
17 /*
18 
19 */
20 const int N = 101;
21 char a[N][N];
22 int ans;
23 int vis[N];
24 char in[] = "D:\\3\\1005\\9.in";
25 char out[] = "D:\\3\\1005\\9.out";
26 char str[] = "0123456789";
27 int main()
28 {
29     
30     //for (int z = 0; z <= 9; ++z)
31     {
32         //in[10] = str[z];
33         //out[10] = str[z];
34         //freopen(in, "r", stdin);
35         //freopen(out, "w", stdout);
36         int n;
37         while (scanf("%d", &n) != EOF)
38         {
39             memset(vis, 0, sizeof(vis));
40             for (int i = 0; i < n; ++i)
41                 scanf("%s", a[i]);
42 
43             ans = 0;
44             for (int i = 0; i < n; ++i)
45             {
46                 bool flag = true;
47                 for (int j = 0; j < n; ++j)
48                 if (a[i][j] == '0')
49                 {
50                     flag = false;
51                     break;
52                 }
53                 if (flag)
54                     ans++;
55             }
56             int tmp;
57             for (int i = 0; i < n; ++i)
58             {
59                 memset(vis, 0, sizeof(vis));
60                 for (int j = 0; j < n; ++j)
61                 {
62                     if (a[i][j] == '0')
63                         vis[j] = true;
64                 }
65                 tmp = 1;
66                 for (int j = 0; j < n; ++j)
67                 {
68                     if (i == j) continue;
69                     bool f = true;
70                     for (int k = 0; k < n; ++k)
71                     if (a[j][k] == '0' && !vis[k])
72                     {
73                         f = false;
74                         break;
75                     }
76                     else if (a[j][k] == '1' && vis[k])
77                     {
78                         f = false;
79                         break;
80                     }
81                     if (f)
82                         tmp++;
83                 }
84                 ans = ans > tmp ? ans : tmp;
85             }
86             printf("%d\n", ans);
87         }
88     }
89     return 0;
90 }
View Code

 

1005

点这里

 

posted @ 2015-06-27 13:59  justPassBy  阅读(200)  评论(0编辑  收藏  举报