Codeforces Round #546 (Div. 2)

淩亂°似流年 2023-06-03 13:52 51阅读 0赞

A. Nastya Is Reading a Book(水)

遍历一下,找到k所在的章数,总的减去已经读的……

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e5+10;
  4. struct node{
  5. int a,b;
  6. }Q[maxn];
  7. int main(){
  8. int n;
  9. cin>>n;
  10. for(int i=1;i<=n;i++){
  11. cin>>Q[i].a>>Q[i].b;
  12. }
  13. int k;
  14. cin>>k;
  15. int ans=0;
  16. for(int i=1;i<=n;i++){
  17. if(Q[i].a<=k&&Q[i].b>=k){
  18. ans=i;
  19. break;
  20. }
  21. }
  22. cout<<n-ans+1<<endl;
  23. return 0;
  24. }

B. Nastya Is Playing Computer Games

贪心,先走到(最左,或者最右)端点,比较走到哪个端点比较小,然后再考虑扔和捡,(比如现在走到最左边)第一次肯定要扔到有一块石头的(假设扔到第二个位置),然后把第二个位置的石头都扔到第一个位置,然后把所有的石头都扔到已经走过的地方;

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e5+10;
  4. int main(){
  5. int n,k;
  6. cin>>n>>k;
  7. if(n==1){
  8. cout<<"2"<<endl;
  9. return 0;
  10. }
  11. else if(n==2){
  12. cout<<"6"<<endl;
  13. return 0;
  14. }
  15. int ans=min(k-1,n-k);
  16. ans+=6;
  17. n-=2;
  18. for(int i=1;i<=n;i++)ans+=3;
  19. cout<<ans<<endl;
  20. return 0;
  21. }

C. Nastya Is Transposing Matrices

题意:给你两个矩阵,问你是否可以根据每个子矩阵的主对角线置换来得到相同的矩阵;

me:想到了每个子矩阵的主对角线应该相同,但是不会处理……

look other:类似桶排序,用map来离散化存值;

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=550;
  4. int n,m;
  5. int a[maxn][maxn],b[maxn][maxn];
  6. map<int,int>mp[1010];
  7. int main(){
  8. ios::sync_with_stdio(false);
  9. cin>>n>>m;
  10. for(int i=1;i<=n;i++){
  11. for(int j=1;j<=m;j++){
  12. cin>>a[i][j];
  13. mp[i+j][a[i][j]]++;
  14. }
  15. }
  16. int flag=1;
  17. for(int i=1;i<=n;i++){
  18. for(int j=1;j<=m;j++){
  19. cin>>b[i][j];
  20. if(mp[i+j][b[i][j]]<=0){
  21. flag=0;
  22. }
  23. else mp[i+j][b[i][j]]--;
  24. }
  25. }
  26. if(flag)cout<<"YES"<<endl;
  27. else cout<<"NO"<<endl;
  28. return 0;
  29. }

D. Nastya Is Buying Lunch

题意:有一个队列,你现在在最后一个,每个人都有一个数,当u,v相邻时可以交换u,v,问你最多能前进几个位置;

当时看错了,以为不相邻也可以交换,导致样例都没理解清楚,就结束了;

解:贪心,从后面一直往前更新,当这两个数满足相邻的时候就可以换;

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=3e5+10;
  4. int n,m,a[maxn],b[maxn];
  5. vector<int>g[maxn];
  6. bool cmp(int u,int v){
  7. return b[u]<b[v];
  8. }
  9. int main(){
  10. ios::sync_with_stdio(false);
  11. cin>>n>>m;
  12. for(int i=1;i<=n;i++){
  13. cin>>a[i];
  14. b[a[i]]=i;
  15. }
  16. for(int i=1;i<=m;i++){
  17. int u,v;
  18. cin>>u>>v;
  19. g[u].push_back(v);
  20. }
  21. for(int i=n;i>0;i--){
  22. int u=a[i];
  23. sort(g[u].begin(),g[u].end(),cmp);
  24. for(auto it:g[u]){
  25. if(b[it]==b[u]+1){
  26. b[u]++;
  27. b[it]--;
  28. }
  29. }
  30. }
  31. cout<<n-b[a[n]]<<endl;
  32. return 0;
  33. }

转载于:https://www.cnblogs.com/lin1874/p/11356643.html

发表评论

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

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

相关阅读

    相关 codeforces-round375-div2

    题目链接:[codeforces round 375 div2][] A题: 读一遍题目就知道是超级水的题目,,就是给你三个坐标,求三个坐标汇集到一个点所走的路程