CF 496D(Tennis Game-O(t*(n/t)复杂度+vector排序)
来源:互联网 发布:大数据专业就业待遇 编辑:程序博客网 时间:2024/04/28 05:44
本题考试使就是想不出非暴力算法。
考完后得知暴力的复杂度是O(t*(n/t))=O(n) ..我一直以为是O(n^2)...
我说为什么有人5minAC,,说多了都是泪
解法:
显然t确定s就确定了,暴力枚举t,然后扫一遍,记得先预处理使得能在O(1)查找1局比赛
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>#include<vector>using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define MAXN (100000+10)long long mul(long long a,long long b){return (a*b)%F;}long long add(long long a,long long b){return (a+b)%F;}long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}typedef long long ll;int n,n1=0,n2=0;int f[MAXN],g[MAXN]; // f/g win'game numint a[MAXN],b[MAXN]; // f/g win f[i] game until ith game endvector<pair<int,int> > ans;int main(){//freopen("Tennis.in","r",stdin);//freopen(".out","w",stdout);MEMI(f) MEMI(g)cin>>n;For(i,n){int t;scanf("%d",&t);if (t&1) f[++n1]=i;else g[++n2]=i;a[i]=n1,b[i]=n2;}For(t,n){bool flag=0;int s1=0,s2=0,cur1=0,cur2=0;for(int cur=0;cur<=n;){int x,y;if (cur1+t>n1&&cur2+t>n2) {flag=1;break;}int now=min(x=f[cur1+t],y=g[cur2+t]);if (x<y) s1++;else s2++;cur1=a[now],cur2=b[now];if (now==n){if (x<y&&s1<s2) flag=1; //x win the last game but totally y winif (x>y&&s1>s2) flag=1; //y win the last game but totally x winif (s1==s2) flag=1; //impossible for rolebreak;} cur=now;}if (!flag) ans.push_back(make_pair(max(s1,s2),t));}sort(ans.begin(),ans.end());printf("%d\n",ans.size());Rep(i,ans.size()) printf("%d %d\n",ans[i].first,ans[i].second);return 0;}
0 0
- CF 496D(Tennis Game-O(t*(n/t)复杂度+vector排序)
- CF - 496D Tennis Game -
- 时间复杂度为O(n+t)的排序
- [Codeforces 496D] Tennis Game (筛法复杂度)
- 算法复杂度函数级T(n)非O(n)分析
- D o t N e t 相关资源 [更新中]
- D o t N e t 相关资源
- 时间复杂度 T(n)
- 算法复杂度T(n)推算
- 【快速】排序, T(n) = O(nlgn),O(n^2) S(n) = O(lgn) --- 不稳定
- 【希尔】排序------ T(n) = O(n^1.5),S(n) = O(1) ---- 不稳定
- Codeforces 496D Tennis Game 枚举+二分
- codeforces 496d Tennis Game 二分
- codeforces 496D Tennis Game(枚举)
- Codeforces 496D Tennis Game(高效)
- Codeforces 496D Tennis Game(二分)
- CodeForces 496 D. Tennis Game【思维】
- T(n) = T(n/2) + O(n)
- 赛尔号11月28日其他更新:感恩节大许愿钻石道具..
- apache lucene solr 官网历史版本下载地址
- 一步之遥!《劲舞团》手机版开启删档封测
- SQL分页语句三方案
- 使用python的内置ctypes模块与c、c++写的dll进行交互
- CF 496D(Tennis Game-O(t*(n/t)复杂度+vector排序)
- Detecting and Exploiting XSS Injections using XSSer Tool
- 练习用基础SQL语句
- VB.NET 几种命名方法总结 章鱼哥出品
- 每天进步一点点_抽奖程序
- Javascript刷新页面的几种方法
- 碰撞检测
- java之10进制转换2,8,16进制
- Android的SDK与ADT不匹配问题