当前位置:   article > 正文

2021 RoboCom 世界机器人开发者大赛-本科组(决赛)题解

2021 RoboCom 世界机器人开发者大赛-本科组(决赛)题解

7-1

  1. #include <bits/stdc++.h>
  2. #define ios ios::sync_with_stdio(0),cin.tie(0)
  3. #define PII pair<int,int>
  4. #define int long long
  5. typedef long long ll;
  6. const int N=1e6+10;
  7. const int inf=0x3f3f3f3f;
  8. using namespace std;
  9. ll n,L;
  10. ll x[N],y[N];
  11. void solve()
  12. {
  13. cin>>n>>L;
  14. for(int i=1;i<=n;i++)
  15. {
  16. if(i&1)
  17. {
  18. cin>>y[i];
  19. x[i]=x[i-1];
  20. }
  21. else
  22. {
  23. cin>>x[i];
  24. y[i]=y[i-1];
  25. }
  26. }
  27. x[n+1]=0,y[n+1]=0;
  28. n++;
  29. ll now=0;
  30. cout<<0<<' '<<0<<'\n';
  31. for(int i=1;i<=n;i++)
  32. {
  33. ll len=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
  34. if(now+len>=L)
  35. {
  36. ll d=L-now;
  37. if(i&1)
  38. {
  39. if(y[i]>y[i-1])
  40. {
  41. if(x[i]==0&&y[i-1]+d==0) continue;
  42. cout<<x[i]<<' '<<y[i-1]+d<<'\n';
  43. ll X=x[i],Y=y[i-1]+d;
  44. while(Y+L<=y[i])
  45. {
  46. if(X==0&&Y+L==0) break;
  47. cout<<X<<' '<<Y+L<<'\n';
  48. Y+=L;
  49. }
  50. now=abs(x[i]-X)+abs(y[i]-Y);
  51. }
  52. else
  53. {
  54. if(x[i]==0&&y[i-1]-d==0) continue;
  55. cout<<x[i]<<' '<<y[i-1]-d<<'\n';
  56. ll X=x[i],Y=y[i-1]-d;
  57. while(Y-L>=y[i])
  58. {
  59. if(X==0&&Y-L==0) break;
  60. cout<<X<<' '<<Y-L<<'\n';
  61. Y-=L;
  62. }
  63. now=abs(x[i]-X)+abs(y[i]-Y);
  64. }
  65. }
  66. else
  67. {
  68. if(x[i]>x[i-1])
  69. {
  70. if(x[i-1]+d==0&&y[i]==0) continue;
  71. cout<<x[i-1]+d<<' '<<y[i]<<'\n';
  72. ll X=x[i-1]+d,Y=y[i];
  73. while(X+L<=x[i])
  74. {
  75. if(X+L==0&&Y==0) break;
  76. cout<<X+L<<' '<<Y<<'\n';
  77. X+=L;
  78. }
  79. now=abs(x[i]-X)+abs(y[i]-Y);
  80. }
  81. else
  82. {
  83. if(x[i-1]-d==0&&y[i]==0) continue;
  84. cout<<x[i-1]-d<<' '<<y[i]<<'\n';
  85. ll X=x[i-1]-d,Y=y[i];
  86. while(X-L>=x[i])
  87. {
  88. if(X-L==0&&Y==0) break;
  89. cout<<X-L<<' '<<Y<<'\n';
  90. X-=L;
  91. }
  92. now=abs(x[i]-X)+abs(y[i]-Y);
  93. }
  94. }
  95. }
  96. else now+=len;
  97. }
  98. }
  99. signed main()
  100. {
  101. //freopen("input.txt","r",stdin);
  102. //freopen("output.txt","w",stdout);
  103. //ios;
  104. int _t=1;
  105. //cin>>_t;
  106. while(_t--) solve();
  107. system("pause");
  108. return 0;
  109. }

7-2

  1. #include <bits/stdc++.h>
  2. #define int long long
  3. const int N=1e5+10;
  4. using namespace std;
  5. typedef long long ll;
  6. int n;
  7. int a[N];
  8. int cal(vector<int>v)
  9. {
  10. int dp[N]={0};
  11. for(int i=0;i<n;i++)
  12. for(int j=0;j<i;j++)
  13. {
  14. if(v[i]>v[j]) dp[i]=max(dp[i],dp[j]+1);
  15. }
  16. int ret=0;
  17. for(int i=0;i<n;i++)
  18. ret=max(ret,dp[i]+1);
  19. return ret;
  20. }
  21. signed main()
  22. {
  23. cin>>n;
  24. for(int i=0;i<n;i++) cin>>a[i];
  25. int malen=1,ans=0;
  26. for(int i=0;i<(1<<n);i++)
  27. {
  28. deque<int>q;
  29. for(int j=0;j<n;j++)
  30. {
  31. if((i>>(n-j))&1) q.push_back(a[j]);
  32. else q.push_front(a[j]);
  33. }
  34. vector<int>v;
  35. for(auto x:q)
  36. v.push_back(x);
  37. int tlen=cal(v);
  38. if(tlen>malen)
  39. {
  40. malen=tlen;
  41. ans=i;
  42. }
  43. if(tlen==n) break;
  44. }
  45. cout<<malen<<'\n';
  46. for(int j=0;j<n;j++)
  47. if((ans>>(n-j))&1) cout<<'R';
  48. else cout<<'L';
  49. cout<<'\n';
  50. return 0;
  51. }

7-3

  1. #include <bits/stdc++.h>
  2. #define int long long
  3. const int N=1e5+10;
  4. using namespace std;
  5. typedef long long ll;
  6. int n,tip,tlog;
  7. unordered_map<string,unordered_map<string,int>>mp;
  8. struct IPS{
  9. string ip;
  10. int num;
  11. bool operator < (const IPS &a) const
  12. {
  13. if(num!=a.num) return num>a.num;
  14. else return ip<a.ip;
  15. }
  16. };
  17. struct Record{
  18. string name;
  19. vector<IPS>ips;
  20. int cnt;
  21. bool operator < (const Record &a) const
  22. {
  23. if(ips.size()!=a.ips.size()) return ips.size()>a.ips.size();
  24. else
  25. {
  26. return name<a.name;
  27. }
  28. }
  29. };
  30. vector<Record>records;
  31. vector<Record>ret;
  32. signed main()
  33. {
  34. cin>>n>>tip>>tlog;
  35. for(int i=0;i<n;i++)
  36. {
  37. string name,ip;
  38. cin>>name>>ip;
  39. mp[name][ip]++;
  40. }
  41. for(auto [a,b]:mp)
  42. {
  43. int cnt=0;
  44. vector<IPS>ips;
  45. for(auto [aa,bb]:b)
  46. {
  47. cnt+=bb;
  48. ips.push_back({aa,bb});
  49. }
  50. sort(ips.begin(),ips.end());
  51. records.push_back({a,ips,cnt});
  52. }
  53. for(auto r:records)
  54. {
  55. if(r.ips.size()>tip&&r.cnt>tlog) ret.push_back(r);
  56. }
  57. if(ret.size())
  58. {
  59. sort(ret.begin(),ret.end());
  60. for(auto r:ret)
  61. {
  62. cout<<r.name<<'\n';
  63. for(auto [ip,num]:r.ips)
  64. {
  65. cout<<ip<<' '<<num<<'\n';
  66. }
  67. }
  68. }
  69. else
  70. {
  71. sort(records.begin(),records.end());
  72. for(int i=0;records[i].ips.size()==records[0].ips.size();i++)
  73. {
  74. cout<<records[i].name<<'\n';
  75. for(auto [ip,num]:records[i].ips)
  76. {
  77. cout<<ip<<' '<<num<<'\n';
  78. }
  79. }
  80. }
  81. system("pause");
  82. return 0;
  83. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/910281
推荐阅读
相关标签
  

闽ICP备14008679号