zoukankan      html  css  js  c++  java
  • ACM-ICPC ShangHai 2014

    A.

        题意:给定一个序列,可以把里面的任意几个数加上K的整数倍,变换之后要求把这个序列从小到大排后变为 数列1,2,3,4,5,6

        解答:最直观的方法是个匹配,但觉得500*100*100*100可能会超

                 不过可以发现A可以变为B only when A%K == B%K && A <= K

         那么对每个可能的余数开个优先队列扫一遍就可以啦

        要被自己蠢死了QAQ

        没清空完就break出QAQ

    #include <cstdio>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    
    using namespace std;
    
    const int N = 105;
    
    
    typedef struct node{ 
        
        int xi,v;
        
        bool operator < (const node &a)const{ 
               if (xi == a.xi) return v < a.v;
             else return  xi > a.xi;
        }
    
    }node;
    
    node newnode(int x,int y){ 
        node tmp;
        tmp.xi = x;
        tmp.v = y;
        return tmp;
    }
    
    int n,m,k;
    
    int a[N],b[N],tmpa[N],tmpb[N]; 
    
    priority_queue<node>Q[N];
    
    
    int main(){
    
        int T; cin >> T;
    
        while (T--){ 
             
             cin >> n >> k;
    
             for (int i = 1;i <= n;i++) scanf("%d",&a[i]);
             
             for (int i = 1;i <= n;i++) b[i] = i;
       
            for (int i = 1;i <= n;i++) Q[a[i]%k].push(newnode(a[i],1));
    
            for (int i = 1;i <= n;i++) Q[b[i]%k].push(newnode(b[i],-1));
           
            int flag = 0; int cnt = 0;
    
            for (int t = 0;t < k;t++,cnt = 0){
              while(!(Q[t].empty())){ 
                      node u = Q[t].top();
                      Q[t].pop();
                      cnt += u.v;
                      if (cnt < 0) flag = 1;
            }
            
            if (cnt != 0) flag = 1; 
            
            }
            
            if (flag) printf("Tom
    ");
                else printf("Jerry
    ");
    
        }
        
    }
  • 相关阅读:
    HarmonyOS (鸿蒙操作系统)你值得拥有
    远端FTP文件与本地文件如何进行Diff
    多线程下载一个大文件的速度更快的真正原因是什么?
    一道有意思的面试题
    BootstrapVue 安装指南
    bash shell数组使用总结
    APP测试之ADB最全指南
    APP测试用例整理
    直播类音视频测试整理
    IOS手机耗电量测试
  • 原文地址:https://www.cnblogs.com/williamchenwl/p/4839356.html
Copyright © 2011-2022 走看看