标签:asi break names ace har style define 变化 技术
挺简单的
题目链接:https://codeforces.com/contest/1311
A:
白给
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 int t; 15 16 int main() { 17 scanf("%d", &t); 18 while (t--) { 19 int a, b, cnt = 0; 20 scanf("%d%d", &a, &b); 21 if (a == b) puts("0"); 22 else if (a < b) { 23 if ((b - a) & 1) puts("1"); 24 else puts("2"); 25 } else { 26 if ((b - a) & 1) puts("2"); 27 else puts("1"); 28 } 29 } 30 return 0; 31 }
B:
扫n次p数组,每次都检查a[p[i]]与a[p[i]+1]是否可交换,再检查a数组即可
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 int t; 15 const int maxn = 110; 16 int n, m, a[maxn], p[maxn]; 17 18 int main() { 19 scanf("%d", &t); 20 while (t--) { 21 scanf("%d%d", &n, &m); 22 for (int i = 1; i <= n; i++) scanf("%d", &a[i]); 23 for (int i = 1; i <= m; i++) scanf("%d", &p[i]); 24 for (int cnt = 1; cnt <= n; cnt++) { 25 for (int i = 1; i <= m; i++) { 26 if (a[p[i]] > a[p[i] + 1]) swap(a[p[i]], a[p[i] + 1]); 27 } 28 } 29 int flag = 1; 30 for (int i = 1; i < n; i++) { 31 if (a[i] > a[i + 1]) { 32 flag = 0; 33 break; 34 } 35 } 36 if (flag) puts("YES"); else puts("NO"); 37 } 38 return 0; 39 }
C:
前缀和预处理一下就行
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 const int maxn = 2e5 + 10; 15 int t, n, m, p[maxn], cnt[maxn][26], ans[26]; 16 char s[maxn]; 17 18 int main() { 19 scanf("%d", &t); 20 while (t--) { 21 scanf("%d%d", &n, &m); 22 scanf("%s", s + 1); 23 for (int i = 0; i <= n; i++) 24 for (int j = 0; j < 26; j++) 25 cnt[i][j] = 0; 26 for (int i = 0; i < 26; i++) ans[i] = 0; 27 for (int i = 1; i <= m; i++) scanf("%d", &p[i]); 28 29 for (int i = 1; i <= n; i++) { 30 cnt[i][s[i] - ‘a‘]++; 31 } 32 for (int i = 1; i <= n; i++) { 33 for (int j = 0; j < 26; j++) { 34 cnt[i][j] += cnt[i - 1][j]; 35 } 36 } 37 for (int i = 1; i <= m; i++) { 38 for (int j = 0; j < 26; j++) { 39 ans[j] += cnt[p[i]][j]; 40 } 41 } 42 for (int i = 0; i < 26; i++) ans[i] += cnt[n][i]; 43 for (int i = 0; i < 26; i++) printf("%d ", ans[i]); 44 puts(""); 45 } 46 return 0; 47 }
D:
比较坑的题,队友还FST了。
题意是给定三个正整数,满足a<=b<=c,可以使三个数变大或变小(不能小于1),问三个数如何变化,能满足a|b且b|c的同时总变化量最小。
由于三个数都不到1e4,所以直接想法是枚举,但枚举的范围很坑。令第一个数的变化范围为[1,c],第二个数为第一个数的i倍且i*a<=2*b(两倍即可,一倍必错),第三个数为第二个数的j倍且j*b<=2*c。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 int t, a, b, c; 15 16 int main() { 17 scanf("%d", &t); 18 while (t--) { 19 int aa, bb, cc, ans = INT_MAX; 20 scanf("%d%d%d", &a, &b, &c); 21 for (int i = 1; i <= c; i++) { 22 int curA = i, curB = 0, curC = 0; 23 for (int j = 1; j * i <= 2 * b; j++) { 24 curB = j * i; 25 for (int k = 1; k * curB <= 2 * c; k++) { 26 curC = k * curB; 27 int tmp = abs(a - curA) + abs(b - curB) + abs(c - curC); 28 if (tmp < ans) { 29 ans = tmp; 30 aa = curA, bb = curB, cc = curC; 31 } 32 } 33 } 34 } 35 printf("%d\n%d %d %d\n", ans, aa, bb, cc); 36 } 37 return 0; 38 }
E:
什么东西,完全没看
F:
题意:一维坐标系上给定n个整点,保证无重复点,每个整点有一个向左或向右的速度且保持不变。定义d(i,j)为点对i,j的最近可能距离(例如若两个点会相遇,则d(i,j)=0),求所有点与其他点最近可能距离之和。
1 /* basic header */ 2 #include <bits/stdc++.h> 3 /* define */ 4 #define ll long long 5 #define pb emplace_back 6 #define mp make_pair 7 #define eps 1e-8 8 #define lson (curpos<<1) 9 #define rson (curpos<<1|1) 10 /* namespace */ 11 using namespace std; 12 /* header end */ 13 14 struct FenwickTree { 15 int n; 16 vector<ll>num; 17 FenwickTree(): n(0) {} 18 FenwickTree(int _n) { 19 n = _n; 20 num.assign(n, 0); 21 } 22 void add(int i, int val) { 23 for (; i < n; i |= i + 1) num[i] += val; 24 } 25 ll sum(int i) { 26 ll ret = 0; 27 for (; i >= 0; i = (i & (i + 1)) - 1) ret += num[i]; 28 return ret; 29 } 30 }; 31 32 int main() { 33 int n; scanf("%d", &n); 34 vector<pair<int, int>>point(n); 35 vector<int>speed; 36 for (int i = 0; i < n; i++) scanf("%d", &point[i].first); 37 for (int i = 0; i < n; i++) { 38 scanf("%d", &point[i].second); 39 speed.push_back(point[i].second); 40 } 41 42 sort(speed.begin(), speed.end()); 43 speed.erase(unique(speed.begin(), speed.end()), speed.end()); 44 sort(point.begin(), point.end()); 45 46 ll ans = 0; 47 FenwickTree cnt(n), sumx(n); 48 for (auto i : point) { 49 i.second = lower_bound(speed.begin(), speed.end(), i.second) - speed.begin(); 50 ans += cnt.sum(i.second) * i.first - sumx.sum(i.second); 51 cnt.add(i.second, 1); 52 sumx.add(i.second, i.first); 53 } 54 printf("%lld\n", ans); 55 return 0; 56 }
Codeforces Round #624 (Div. 3)
标签:asi break names ace har style define 变化 技术
原文地址:https://www.cnblogs.com/JHSeng/p/12363216.html