ACM-ICPC ShangHai 2014
2015-09-25 20:20
525 查看
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
题意:给定一个序列,可以把里面的任意几个数加上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 ,b ,tmpa ,tmpb ; priority_queue<node>Q ; 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\n"); else printf("Jerry\n"); } }
相关文章推荐
- LeetCode-Contains DuplicateI
- saiku环境搭建
- saiku环境搭建
- HDU 4819 Mosaic(二维线段树+单点更新)
- hdu 1022 Train Problem I
- SharePoint API测试系列——Manage SharePoint Site Policy & Expiration Email with CSOM API
- file_put_contents() failed to open stream: Permission denied 问题解决(生成日志文件)
- Mac 下安装及配置 ProxyChains-NG 实现终端下代理
- [[NSBundle mainBundle]pathForResource:@"XXX" ofType:@"db"]为nil的解决办法
- HDU 1023.Train Problem II【大卡特兰数】【9月25】
- typeof、offsetof、container_of的解释
- Handler sendMessage 与 obtainMessage (sendToTarget)比较
- Linux0.11内核--内存组织和进程结构 http://blog.csdn.net/x_white/article/details/8459611
- 解决:对COM 组件的调用返回了错误 HRESULT E_FAIL
- Root Container #Facebook Relay文档翻译#
- Saiku汉化工作记录
- Rails 4-2-stable 参考手册 (Beta)
- [LeetCode]Container With Most Water
- Package Control:There are no packages available for installation
- Terminal initialization failed; falling back to unsupported