AtCoder Beginner Contest 121 題解
阿新 • • 發佈:2019-03-28
print 分享 題目 contest 題解 scanf alt strong pri
題目鏈接: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);View Code11 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> 3View Code4 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 }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
AtCoder Beginner Contest 121 題解