AtCoder Beginner Contest 139

「爱情、让人受尽委屈。」 2024-04-18 09:05 203阅读 0赞

文章目录

  • [A - Tenki](https://atcoder.jp/contests/abc139/tasks/abc139\_a)
  • [B - Power Socket](https://atcoder.jp/contests/abc139/tasks/abc139\_b)
  • [C - Lower](https://atcoder.jp/contests/abc139/tasks/abc139\_c)
  • [D - ModSum](https://atcoder.jp/contests/abc139/tasks/abc139\_d)
  • [E - League](https://atcoder.jp/contests/abc139/tasks/abc139\_e)
  • [F - Engines](https://atcoder.jp/contests/abc139/tasks/abc139\_f)

A - Tenki

比较一下

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<int ,int> P;
  5. const int INF = 0x3f3f3f3f;
  6. const int MAXN = 1e3+7;
  7. int main() {
  8. string s,t;
  9. while(cin>>s>>t) {
  10. int ans = 0;
  11. for(int i=0;i<3;++i)
  12. if(s[i]==t[i])
  13. ans ++;
  14. cout<<ans<<endl;
  15. }
  16. return 0;
  17. }

B - Power Socket

模拟一下

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<int ,int> P;
  5. const int INF = 0x3f3f3f3f;
  6. const int MAXN = 1e3+7;
  7. int main() {
  8. int a,b;
  9. while(cin>>a>>b) {
  10. int ans = 0,num = 0;
  11. // num = (b-1)/(a-1);
  12. while(ans<b) {
  13. num++;
  14. if(ans+a<b) ans += a-1;
  15. else ans += a;
  16. }
  17. if(b==1) num = 0;
  18. cout<<num<<endl;
  19. }
  20. return 0;
  21. }

C - Lower

找连续不递增子段的最大长度

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<int ,int> P;
  5. const int INF = 0x3f3f3f3f;
  6. const int MAXN = 1e5+7;
  7. int dp[MAXN];
  8. int a[MAXN];
  9. int main() {
  10. int n;
  11. while(cin>>n) {
  12. for(int i=0;i<n;++i)
  13. cin>>a[i];
  14. int ans = 0;
  15. int num = 0;
  16. for(int i=1;i<n;++i) {
  17. if(a[i]<=a[i-1]) num++;
  18. else num = 0;
  19. ans = max(ans,num);
  20. }
  21. cout<<ans<<endl;
  22. }
  23. return 0;
  24. }

D - ModSum

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef pair<int ,int> P;
  5. const int INF = 0x3f3f3f3f;
  6. const int MAXN = 1e5+7;
  7. int dp[MAXN];
  8. int a[MAXN];
  9. int main() {
  10. ll n;
  11. while(cin>>n)
  12. cout<<(ll)n*(n-1)/2<<endl;
  13. return 0;
  14. }

E - League

这个题的意思是,给你一个的矩阵
矩阵一共有 n n n 行,每行有 n − 1 n-1 n−1个数
第i行表示第 i i i 个玩家,他进行网球比赛的次序就是这一行的数字,需要严格的与从左到右这些人比赛。
每个人每天最多只能参加一场比赛
问这些人比赛完的最小天数

如果不存在输出-1

用队列模拟,
要求最后所有队列都清空

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int MAXN = 1e3+7;
  5. int a[MAXN][MAXN];
  6. int b[MAXN];
  7. bool vis[MAXN];
  8. queue<int> Q[MAXN];
  9. int main(){
  10. int n;
  11. cin>>n;
  12. for(int i=0;i<n;++i){
  13. b[i] = 0;
  14. for(int j=0;j<n-1;++j) {
  15. cin>>a[i][j];
  16. a[i][j]--;
  17. Q[i].push(a[i][j]);
  18. }
  19. }
  20. int ans = 0;
  21. while(true) {
  22. bool flag = 0;
  23. for(int i=0;i<n;++i) {
  24. if(Q[i].empty()) continue;
  25. if(Q[Q[i].front()].front()==i) {
  26. b[i] = b[Q[i].front()] = max(b[i],b[Q[i].front()]) + 1;
  27. Q[Q[i].front()].pop();
  28. Q[i].pop();
  29. flag = 1;
  30. }
  31. }
  32. if(!flag) {
  33. cout<<-1<<endl;
  34. return 0;
  35. }
  36. int num = 0;
  37. for(int i=0;i<n;++i)
  38. num += Q[i].size();
  39. if(num==0) break;
  40. }
  41. for(int i=0;i<n;++i)
  42. ans = max(ans, b[i]);
  43. cout<<ans<<endl;
  44. return 0;
  45. }

F - Engines

将这n个二元组看做n个向量。
移动方式遵循平行四边形定则。
所以两个向量夹角越小,相加形成的和向量模长就越大。
所以将这些向量按照极角排序。
选择的向量肯定是一个区间。
枚举左右端点,求最大值即可。

  1. /*
  2. 将这n个二元组看做n个向量。
  3. 移动方式遵循平行四边形定则。
  4. 所以两个向量夹角越小,相加形成的和向量模长就越大。
  5. 所以将这些向量按照极角排序。
  6. 选择的向量肯定是一个区间。
  7. 枚举左右端点,求最大值即可。
  8. */
  9. #include<bits/stdc++.h>
  10. using namespace std;
  11. typedef long long ll;
  12. const int MAXN = 1e2+5;
  13. struct Point{
  14. int x,y;
  15. }p[MAXN];
  16. bool cmp(Point a,Point b) {
  17. return atan2(a.y,a.x) < atan2(b.y, b.x);
  18. }
  19. int nx[MAXN];//让它循环
  20. int main() {
  21. int n;
  22. cin>>n;
  23. for(int i=1;i<=n;++i) cin>>p[i].x>>p[i].y;
  24. for(int i=1;i<=n;++i) nx[i] = i+1; nx[n] = 1;
  25. sort(p+1,p+n+1,cmp);
  26. ll ans=0;
  27. for(int i=1;i<=n;++i) {
  28. ll x = p[i].x, y = p[i].y;
  29. ans = max(ans, x * x + y * y);
  30. for(int j=nx[i];j!=i;j = nx[j]) {
  31. x += p[j].x;
  32. y += p[j].y;
  33. ans = max(ans, x * x + y * y);
  34. }
  35. }
  36. printf("%.10lf\n",sqrt(ans));
  37. return 0;
  38. }

发表评论

表情:
评论列表 (有 0 条评论,203人围观)

还没有评论,来说两句吧...

相关阅读