E. Time Limit Exceeded?
来源:互联网 发布:绵阳涪城广电网络热线 编辑:程序博客网 时间:2024/04/29 21:00
ACM Arabella Collegiate Programming Contest 2015
有两种方法:
一:记录每个数出现的次数,然后从1~10000扫描如果i<32时,就是前32个出现的次数抽两个的意思,当i>32,就是加上本身的排列和i-32~i之间的数的抽取,说的我自己都不知道什么意思~~~
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namespace std;#define N 10010int n,t,a[N],c[N];int main(){ scanf("%d",&t); while(t--) { scanf("%d",&n); int d; memset(a,0,sizeof(a)); memset(c,0,sizeof(c)); for(int i=1;i<=n;i++) { scanf("%d",&d); a[d]++; } int count=0; for(int i=1;i<10001;i++) c[i]=c[i-1]+a[i]; count+=c[32]*(c[32]-1)/2; for(int i=33;i<10001;i++) { count+=(c[i-1]-c[i-32])*a[i]+a[i]*(a[i]-1)/2; } printf("%d\n",count); } return 0;}第二种方法:
想得有点久,当然我是看别人的。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define N 10010#define inf 0x3f3f3fint a[N];int main(){ int t,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i]); } sort(a,a+n); int c=0,j=0; for(int i=1;i<n;i++) //主要代码 { while(a[i]-a[j]>=32) j++; c+=i-j; } cout<<c<<endl; } return 0;}
洗澡去了,,,,要断网了。。。
点击打开链接
0 0
- E. Time Limit Exceeded?
- uva131 Time limit exceeded
- Time Limit Exceeded 解析
- Time Limit Exceeded
- SPOJ Time Limit Exceeded
- 避免 Time Limit Exceeded
- Time Limit Exceeded 原因
- ACM中关于Output Limit Exceeded和Time Limit Exceeded
- ACM中关于Output Limit Exceeded和Time Limit Exceeded
- 10044-Erdos number Time limit exceeded
- POJ 1423. BigNumber (Time Limit Exceeded)
- spoj 2829 Time Limit Exceeded (DP)
- Sicily 1063 Time Limit Exceeded我日
- 关于Time Limit Exceeded可能的原因
- UVa694 - The Collatz Sequence:Time limit exceeded
- 4.【Hard】LRU Cache--Time Limit Exceeded
- Time limit exceeded 出现的原因
- POJ 1629 Time Limit Exceeded getchar() vs scanf()
- C语言学习心得一:__stdcall、__cdcel和__fastcall三者的区别
- EditPlus编写java的大括号自动补全
- AIDL与Binder与Messenger的使用区别!
- 27. Remove Element
- 【hdu2546】饭卡——01背包
- E. Time Limit Exceeded?
- 深入分析 Java I/O 的工作机制
- leetcode: Best Meeting Point
- 34.Oracle深度学习笔记——12C的AWR初步解读
- 基于python3的杭电HDU ACM AC自动机
- OC的优缺点
- git常用命令
- QuickAdapter重构
- Messages ListFragment