题意:网球有一方赢t球算一场,先赢s场的获胜。数列arr(长度为n)记录了每场的胜利者,问可能的t和s。

首先,合法的场景必须:

1两方赢的场数不一样多。

2赢多的一方最后一场必须赢。

3最后一场必须打满(即胜利者赢了t球)

首先要两个sum数组记录arr前i个元素中有多少个1,多少个2。先枚举t(从1-n),当前位置从cur=1开始,要查cur到多少(记为pos1),有t个1,到多少(pos2),有t个2。这个在sum数组里用lower_bound查。让cur=(pos1,pos2中小的那个)继续循环。如果最后pos1,pos2都等于n+1,说明最后两者的数量都不足t个,是不合法的。

原本我用二分右端点+线段树查1和2数量的方法,这样比sum数组+lower_bound的方法多了一个log(一个是logn*logn,一个是logn),结果第23个案例(n=100000)超时,我生成了一个十万的序列,结果用时3s,只比限制的2s多1s。可见这题连logn都要卡。换数组后变为200ms过。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
int psum[][SZ]; int main()
{
//std::ios::sync_with_stdio(0);
//freopen("d:\\1.txt","r",stdin);
vector<pair<int,int>> res;
int n;
//cin>>n;
scanf("%d",&n);
vector<int> vct(n+);
for(int i=;i<=n;++i)
{
//cin>>vct[i];
scanf("%d",&vct[i]);
}
psum[][]=vct[]==;
psum[][]=vct[]==;
for(int i=;i<=n;++i)
{
psum[][i]=(vct[i]==)+(psum[][i-]);
psum[][i]=(vct[i]==)+(psum[][i-]);
}
//for(int i=1;i<=n;++i)cout<<psum[2][i]<<endl;
//cout<<qry(1,n,1,1,4)<<endl;
for(int i=;i<=n;++i)
{
int cur=;
bool fail=;
int win1=,win2=,last=;
for(;cur<=n;)
{
int lo=cur,hi=n+;
int pos1,pos2;
//for(;lo<hi;)
//{
// int mid=(lo+hi)/2;
pos1=lower_bound(psum[]+,psum[]+n+,psum[][cur-]+i)-(psum[]);
pos2=lower_bound(psum[]+,psum[]+n+,psum[][cur-]+i)-(psum[]);
//cout<<"m: "<<cur<<" "<<pos1<<" "<<pos2<<endl;
// if(max(num1,num2)>=i)
// {
// hi=mid;
// }
// else lo=mid+1;
//}
//num1=psum[1][lo]-psum[1][cur-1];
//num2=(lo-cur+1-num1);
if(pos1<pos2)++win1;
else ++win2;
last=(pos1<pos2?:);
//if(i==2)cout<<"lo: "<<lo<<endl;
if(pos1==pos2)
{
fail=;
break;
}
cur=min(pos1,pos2)+;
}
if(win1==win2)fail=;
if(win1>win2&&last!=)fail=;
if(win2>win1&&last!=)fail=;
//cout<<"i:"<<i<<" "<<win1<<" "<<win2<<endl;
if(!fail)
{
res.push_back(make_pair(max(win1,win2),i));
}
}
// int num1=count(vct.begin()+1,vct.end(),1);
// int num2=count(vct.begin()+1,vct.end(),2);
// if(num1!=num2)
// {
// int big=num1>num2?1:2;
// if(big==vct[vct.size()-1])res.push_back(make_pair(max(num1,num2),1));
// }
sort(res.begin(),res.end());
cout<<res.size()<<endl; for(int i=;i<res.size();++i)
{
printf("%d %d\n",res[i].first,res[i].second);
//cout<<res[i].first<<" "<<res[i].second<<endl;
}
return ;
}

codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)的更多相关文章

  1. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  2. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  3. Codeforces Round #283 (Div. 2) D. Tennis Game(模拟)

    D. Tennis Game time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #283 Div.2 D Tennis Game --二分

    题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛.求有多少种 t 和 s 的分配方案并输出t,s. 解法: 因为要知道 ...

  5. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #283 (Div. 2)

    A:暴力弄就好,怎么方便怎么来. B:我们知道最多加10次, 然后每次加1后我们求能移动的最小值,大概O(N)的效率. #include<bits/stdc++.h> using name ...

  8. codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)

    题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...

  9. Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题

    B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. LoadRunner 自动关联、手动关联的帖子

    https://www.guru99.com/correlation-in-loadrunner-ultimate-guide.html 这个网页里介绍了关联的概念,自动关联和手动关联的知识...

  2. 让360双核浏览器默认极速模式,避免采用IE模式无法正常访问html5网页的解决办法

    让360双核浏览器默认极速模式,避免采用IE模式无法正常访问html5网页的解决办法 用Meta标签代码让360双核浏览器默认极速模式不是兼容模式<meta name="rendere ...

  3. 配置mysql主从数据库

    来源地址:https://www.cnblogs.com/alvin_xp/p/4162249.html Mysql主从配置,实现读写分离 大型网站为了软解大量的并发访问,除了在网站实现分布式负载均衡 ...

  4. P3008 [USACO11JAN]道路和飞机Roads and Planes

    P3008 [USACO11JAN]道路和飞机Roads and Planes Dijkstra+Tarjan 因为题目有特殊限制所以不用担心负权的问题 但是朴素的Dijkstra就算用堆优化,也显然 ...

  5. 三步搞定 opencv 初始环境设定

    一.设定bin的初始位置:比如我的电脑 D:\安装程序\opencv\build\x86\vc10\bin      H:\生产力工具\opencv\build\x86\vc10\bin D:\安装程 ...

  6. CodeForces 471D MUH and Cube Walls -KMP

    Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of ...

  7. VS编译器之间相互打开的技巧

    例如:VS2010的工程在VS2012上打开,在工程属性里面 选择“常规” --> "平台工具集中"   选择 正在打开版本的型号.

  8. 【资源】分享一个最新版sublime 3143的注册码,亲测可用

    注:请勿用作商业用途,有能力者请购买正版!!! —– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD9 ...

  9. Mysql数据库基础知识

    什么是Mysql数据库 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQ ...

  10. 为 Android 8.0 添加开机启动脚本【转】

    本文转载自:https://zhuanlan.zhihu.com/p/32868074 本人对于 SELinux for Android 理解不深,下文中的各文件及安全规则虽都是我所编写,但也是一边查 ...