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 }

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 }

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 }

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 }

原文地址:https://www.cnblogs.com/Bil369/p/10612082.html

时间: 2024-11-09 09:47:48

AtCoder Beginner Contest 121 题解的相关文章

AtCoder Beginner Contest 154 题解

人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one

【ATcoder】AtCoder Beginner Contest 161 题解

题目链接:AtCoder Beginner Contest 161 原版题解链接:传送门 A - ABC Swap 这题太水,直接模拟即可. 1 #include <iostream> 2 using namespace std; 3 int main() { 4 int a, b, c; 5 cin >> a >> b >> c; 6 swap(a, b); 7 swap(a, c); 8 cout << a << " &

AtCoder Beginner Contest 115 题解

题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit : 1024MB Score : 100 points Problem Statement In some other world, today is December D-th. Write a program that prints Christmas if D=25, Christmas E

【ATcoder】AtCoder Beginner Contest 159题解

官方题解 落谷链接 ATC链接 A - The Number of Even Pairs 题意 给你两个数$n, m$代表有$n$个偶数,$m$个奇数.让你输出$n$个偶数$m$个奇数从中任选两个数(没有顺序)相加结果为偶数的个数. 题解 相加为偶数只有偶加偶和奇加奇两种情况,其实就是在$n$个数中取两个($C\binom{2}{n}$),在$m$个数中取两个($C\binom{2}{m}$). 时间复杂度$O(1)$ 1 #include <iostream> 2 using namespa

AtCoder Beginner Contest 144 题解

传送门 $cf$ 自闭了,打 $abc$ 散散心 A - 9x9 ...这个有什么好讲的吗,题目看懂就会做了 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char

AtCoder Beginner Contest 160题解

A. 签到题1. #include<bits/stdc++.h> #define fi first #define sd second #define lson (nd<<1) #define rson (nd+nd+1) #define PB push_back #define mid (l+r>>1) #define MP make_pair #define SZ(x) (int)x.size() using namespace std; typedef long

AtCoder Beginner Contest 155 简要题解

AtCoder Beginner Contest 155 A:签到失败,WA一次. int main() { int a, b, c; cin >> a >> b >> c; if(a == b && b == c) cout << "No"; else if(a == b || a == c || b == c) cout << "Yes"; else cout << &quo

AtCoder Beginner Contest 136

AtCoder Beginner Contest 136 Contest Duration : 2019-08-04(Sun) 20:00 ~ 2019-08-04(Sun) 21:40 Website: AtCoder BC-136 后面几题都挺考思考角度D. C - Build Stairs 题目描述: 有n座山从左到右排列,给定每一座山的高度\(Hi\),现在你可以对每座山进行如下操作至多一次:将这座山的高度降低1. 问是否有可能通过对一些山进行如上操作,使得最后从左至右,山的高度呈不下降

AtCoder Beginner Contest 103 D(贪心)

AtCoder Beginner Contest 103 D 题目大意:n个点,除第n个点外第i与第i+1个点有一条边,给定m个a[i],b[i],求最少去掉几条边能使所有a[i],b[i]不相连. 按右端点从小到大排序,如果当前选的去掉的边在区间内,那么符合条件,否则ans++,并贪心地把去掉的边指向右端点,因为前面的区间都满足条件了,所以要去掉的边要尽量向右移使其满足更多的区间. 1 #include <iostream> 2 #include <cstdio> 3 #incl