Codeforces Round #558 (div. 2)
作者:互联网
bc两题居然都有小题,有点烦。
题目链接:http://codeforces.com/contest/1163
A:
本场唯一温暖人心。
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define int_inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 int n, m; 41 42 int main() 43 { 44 scanf("%d%d", &n, &m); 45 if (!m) puts("1"); 46 else 47 { 48 if (m <= n / 2) printf("%d\n", m); 49 else printf("%d\n", n - m); 50 } 51 return 0; 52 }View Code
B easy & hard:
读懂题之后其实也挺傻的。
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define int_inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 const int maxn = 1e5 + 10; 41 int n, a[maxn], cnt[maxn], b[maxn], used, ans = 1; 42 43 int main() 44 { 45 scanf("%d", &n); 46 rep1(i, 1, n) scanf("%d", &a[i]); 47 rep1(i, 1, n) 48 { 49 if (!cnt[a[i]]) used++; 50 b[cnt[a[i]]]--; cnt[a[i]]++; b[cnt[a[i]]]++; 51 if (b[cnt[a[i]]] == used - 1 && b[cnt[a[i]] + 1] == 1) ans = i; 52 if (b[cnt[a[i]]] == used - 1 && b[1] == 1) ans = i; 53 if (b[cnt[a[i]]] == 1 && b[cnt[a[i]] - 1] == used - 1) ans = i; 54 if (b[cnt[a[i]]] == used && i != n) ans = i + 1; 55 } 56 printf("%d\n", ans); 57 return 0; 58 }View Code
C easy & hard:
easy版本暴力就可以了,hard版本稍难一些。从n<=1000就可以猜到大概是个O(n^2)的做法。
1 /* basic header */ 2 #include <iostream> 3 #include <cstdio> 4 #include <cstdlib> 5 #include <string> 6 #include <cstring> 7 #include <cmath> 8 #include <cstdint> 9 #include <climits> 10 #include <float.h> 11 /* STL */ 12 #include <vector> 13 #include <set> 14 #include <map> 15 #include <queue> 16 #include <stack> 17 #include <algorithm> 18 #include <array> 19 #include <iterator> 20 /* define */ 21 #define ll long long 22 #define dou double 23 #define pb emplace_back 24 #define mp make_pair 25 #define fir first 26 #define sec second 27 #define sot(a,b) sort(a+1,a+1+b) 28 #define rep1(i,a,b) for(int i=a;i<=b;++i) 29 #define rep0(i,a,b) for(int i=a;i<b;++i) 30 #define repa(i,a) for(auto &i:a) 31 #define eps 1e-8 32 #define inf 0x3f3f3f3f 33 #define ll_inf 0x7f7f7f7f7f7f7f7f 34 #define lson curPos<<1 35 #define rson curPos<<1|1 36 /* namespace */ 37 using namespace std; 38 /* header end */ 39 40 const int maxn = 1e3 + 10; 41 struct Point 42 { 43 int x, y; 44 }; 45 46 map<pair<pair<ll, ll>, pair<ll, ll> >, ll>m; 47 map<pair<ll, ll>, ll>mm; 48 Point p[maxn]; 49 int n; 50 ll ans = 0; 51 52 int main() 53 { 54 m.clear(); mm.clear(); 55 scanf("%d", &n); 56 for (int i = 1; i <= n; i++) 57 { 58 scanf("%lld%lld", &p[i].x, &p[i].y); 59 for (int j = 1; j < i; j++) 60 { 61 int xx = p[i].x - p[j].x, yy = p[i].y - p[j].y, zz = xx * p[j].y - yy * p[j].x; 62 int gcd = __gcd(xx, yy), gcd2 = __gcd(xx, zz); 63 if (!xx) 64 m[ {{xx / gcd, yy / gcd}, {p[i].x, inf}}]++; 65 else 66 m[ {{xx / gcd, yy / gcd}, {xx / gcd2, zz / gcd2}}]++; 67 } 68 } 69 for (auto i : m) 70 mm[ {i.fir.fir.fir, i.fir.fir.sec}]++; 71 for (auto id : m) 72 ans += (int)m.size() - mm[ {id.fir.fir.fir, id.fir.fir.sec}]; 73 printf("%lld\n", ans / 2); 74 return 0; 75 }View Code
D:
看了题目莫得想法,往右下角一看tag是dp string,打扰了。
标签:558,int,ll,Codeforces,long,pair,div,include,define 来源: https://www.cnblogs.com/JHSeng/p/10845164.html