AtCoder Beginner Contest 121 题解

题目链接:https://atcoder.jp/contests/abc121

 

A White Cells

分析:题目数据规模很小,直接暴力修改都可以。或者可以推出公式.

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int a[25][25] = {0};
 9     int H, W, h, w;
10     scanf("%d %d", &H, &W);
11     scanf("%d %d", &h, &w);
12     for(int i = 0; i < h; ++i)
13         for(int j = 0; j < W; ++j)
14             a[i][j] = 1;
15     for(int i = 0; i < w; ++i)
16         for(int j = 0; j < H; ++j)
17             a[j][i] = 1;
18     int ans = 0;
19     for(int i = 0; i < H; ++i)
20     {
21         for(int j = 0; j < W; ++j)
22         {
23             if(a[i][j] == 0)
24                 ++ans;
25         }
26     }
27     printf("%d\n", ans);
28     return 0;
29 }
View Code

 

B Can you solve this?

分析:模拟即可。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int n, m, c;
 9     scanf("%d %d %d", &n, &m, &c);
10     int b[25];
11     for(int i = 0; i < m; ++i)
12         scanf("%d", &b[i]);
13     int ans = 0;
14     for(int i = 0; i < n; ++i)
15     {
16         int tmp, sum = 0;
17         for(int j = 0; j < m; ++j)
18         {
19             scanf("%d", &tmp);
20             sum += tmp * b[j];
21         }
22         if(sum + c > 0)
23             ++ans;
24     }
25     printf("%d\n", ans);
26     return 0;
27 }
View Code

 

C Energy Drink Collector

分析:贪心+模拟即可。

代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 typedef long long ll;
 8 
 9 struct store
10 {
11     ll a;
12     ll b;
13 }sl[100005];
14 
15 bool cmp(store x, store y)
16 {
17     return x.a < y.a;
18 }
19 
20 int main()
21 {
22     ll n, m;
23     cin>>n>>m;
24     for(int i = 0; i < n; ++i)
25     {
26         cin>>sl[i].a>>sl[i].b;
27     }
28     sort(sl, sl + n, cmp);
29     ll ans = 0, sum = 0;
30     for(int i = 0; i < n; ++i)
31     {
32         if(sum + sl[i].b >= m)
33         {
34             ans += (m - sum) * sl[i].a;
35             break;
36         }
37         else
38         {
39             sum += sl[i].b;
40             ans += sl[i].b * sl[i].a;
41         }
42     }
43     cout<<ans<<endl;
44     return 0;
45 }
View Code

 

D XOR World

分析:首先异或运算有个性质:,这样我们只要看具有的性质即可。打表可以发现有以下规律:

据此,我们可以写出代码。注意对于A为0要特判一下。

代码:

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 
 7 ll myxor(ll a)
 8 {
 9     if(a % 4 == 1)
10         return 1;
11     else if(a % 4 == 2)
12         return a + 1;
13     else if(a % 4 == 3)
14         return 0;
15     else
16         return a;
17 }
18 
19 int main()
20 {
21     ll a, b;
22     cin>>a>>b;
23     if(a == 0)
24         cout<<b<<endl;
25     else
26         cout<<((myxor(b))^(myxor(a-1)))<<endl;
27     return 0;
28 }
View Code
posted @ 2019-03-27 23:37  Bil369  阅读(296)  评论(0编辑  收藏  举报