第一次打atcoder,还因为开会的原因被迫让了半小时。Beginning Contest比想象中要简单。
题目链接:https://atcoder.jp/contests/abc126
A:
给定一个只含有大写字母的字符串,把第k位变为小写并输出字符串。这比cf div3 a还傻。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int n, k; 21 string s; 22 23 int main() 24 { 25 cin >> n >> k >> s; 26 for (int i = 0; i < n; i++) 27 if (i != k - 1) cout << s[i]; 28 else cout << (char)(s[i] + 'a' - 'A'); 29 cout << endl; 30 return 0; 31 }
B:
有点卡题意,看了样例才懂在干什么。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 string s; 21 22 int hefa(int x, int y) 23 { 24 if ((x * 10 + y) <= 12 && (x * 10 + y) > 0) return 1; else return 0; 25 } 26 27 int main() 28 { 29 cin >> s; 30 int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0'; 31 if (hefa(a, b) && hefa(c, d)) puts("AMBIGUOUS"); 32 else if (hefa(a, b) && !hefa(c, d)) puts("MMYY"); 33 else if (!hefa(a, b) && hefa(c, d)) puts("YYMM"); 34 else puts("NA"); 35 return 0; 36 }
C:
O(n)暴力加都可以过的弱智题。但这题如果故意卡精度就会很恶心。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 int n, k; 21 double ans = 0; 22 23 int main() 24 { 25 cin >> n >> k; 26 for (int i = 1; i <= n; i++) 27 { 28 if (i >= k) ans += 1.0 / n; 29 else 30 { 31 int tmp = i, cnt = 0; 32 while (tmp < k) tmp *= 2, cnt++; 33 ans += 1.0 / n * pow(0.5, (double)cnt); 34 } 35 } 36 printf("%.9f ", ans); 37 return 0; 38 }
D:
一开始我还想用sb做法去搞,后来还是老老实实bfs了。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 2000000; 21 struct Edge 22 { 23 int u, v, w; 24 } edge[maxn]; 25 int n, cnt, ans[maxn], vis[maxn]; 26 vector<int> g[maxn]; 27 28 void addedge(int u, int v, int w) 29 { 30 edge[++cnt].u = u; 31 edge[cnt].v = v; 32 edge[cnt].w = w; 33 g[u].push_back(cnt); 34 } 35 36 void bfs() 37 { 38 queue<int> Q; 39 Q.push(1); 40 while (!Q.empty()) 41 { 42 int x = Q.front(); 43 Q.pop(); 44 if (vis[x]) continue; 45 vis[x] = 1; 46 for (int i = 0; i < g[x].size(); i++) 47 { 48 int cur = g[x][i]; 49 if (!vis[edge[cur].v]) 50 { 51 if (edge[cur].w % 2 == 0) 52 { 53 ans[edge[cur].v] = ans[x]; 54 55 } 56 else 57 { 58 ans[edge[cur].v] = 1 - ans[x]; 59 } 60 Q.push(edge[cur].v); 61 } 62 } 63 } 64 } 65 66 int main() 67 { 68 scanf("%d", &n); 69 for (int i = 1; i < n; i++) 70 { 71 int u, v, w; 72 scanf("%d%d%d", &u, &v, &w); 73 addedge(u, v, w); addedge(v, u, w); 74 } 75 bfs(); 76 for (int i = 1; i <= n; i++) printf("%d ", ans[i]); 77 return 0; 78 }
E:
弱智题,因为只有1和2,并查集秒杀。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define dou double 6 #define pb emplace_back 7 #define mp make_pair 8 #define sot(a,b) sort(a+1,a+1+b) 9 #define rep1(i,a,b) for(int i=a;i<=b;++i) 10 #define rep0(i,a,b) for(int i=a;i<b;++i) 11 #define eps 1e-8 12 #define int_inf 0x3f3f3f3f 13 #define ll_inf 0x7f7f7f7f7f7f7f7f 14 #define lson curPos<<1 15 #define rson curPos<<1|1 16 /* namespace */ 17 using namespace std; 18 /* header end */ 19 20 const int maxn = 1e5 + 10; 21 int fa[maxn], ans = 0, n, m; 22 23 int find(int x) 24 { 25 return fa[x] == x ? x : fa[x] = find(fa[x]); 26 } 27 28 int main() 29 { 30 scanf("%d%d", &n, &m); 31 rep1(i, 1, n) fa[i] = i; 32 rep1(i, 1, m) 33 { 34 int x, y, k; 35 scanf("%d%d%d", &x, &y, &k); 36 int px = find(x), py = find(y); 37 fa[px] = py; 38 } 39 rep1(i, 1, n) if (find(i) == i) ans++; 40 printf("%d ", ans); 41 return 0; 42 }
F:
构造题,完全没想法。代码via. yang12138。hrynb!
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 5 int main(){ 6 7 int n,k; 8 cin>>n>>k; 9 //baoli(n,k); 10 //return 0; 11 if(n==1){ 12 if(k>0) printf("-1 "); 13 else printf("0 0 1 1 "); 14 return 0; 15 } 16 int all=(1<<n); 17 18 if(k<all){ 19 if(k==0){ 20 for(int i=0;i<all;i++) printf("%d %d ",i,i); 21 return 0; 22 } 23 for(int i=1;i<all;i++){ 24 if(i==k) continue; 25 printf("%d ",i); 26 } 27 printf("%d ",k); 28 for(int i=all-1;i>=1;i--){ 29 if(i==k) continue; 30 printf("%d ",i); 31 } 32 printf("0 %d 0 ",k); 33 return 0; 34 } 35 else printf("-1 "); 36 37 return 0; 38 }