题意:网球有一方赢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. linux常用命令:df 命令

    linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...

  2. DOS操作系统的历史

    昨日(7月27日),微软公司的DOS操作系统迎来了30岁生日. DOS是历史上一个划时代的产品,标识着PC(个人电脑)的崛起和普及,对计算机行业影响深远. 只有了解DOS的历史,才能理解今天的计算机工 ...

  3. Azkaban 入门

    需求 实际当中经常有这些场景:每天有一个大任务,这个大任务可以分成A,B,C,D四个小任务,A,B任务之间没有依赖关系,C任务依赖A,B任务的结 果,D任务依赖C任务的结果.一般的做法是,开两个终端同 ...

  4. MD5验签同一字符串得到不同的MD5签名值可能问题之一

    public static String md555(String plainText) throws UnsupportedEncodingException { byte[] secretByte ...

  5. java,swift,oc互相转换,html5 web开发跨平台

    java,swift,oc互相转换,html5 web开发跨平台 写一个java->swift的程序,这个程序是做跨平台系统的核心部分swift和oc到java也在考虑之列Swift->J ...

  6. vm #set、日期截取、#foreach&#if

    <div class="form_row"> <label>状态:</label> #if ($!cp.runState =='t') #set ...

  7. 计算概论(A)/基础编程练习2(8题)/3:计算三角形面积

    #include<stdio.h> #include<math.h> int main() { // 声明三角形的三个顶点坐标和面积 float x1, y1, x2, y2, ...

  8. SNMP学习笔记之SNMP树形结构介绍

    Basic command of SNMP: GET: The GET operation is a request sent by the manager to the managed device ...

  9. Js删除字符串中的指定字符串

    案例一. 比如:原字符串 var StringFirst = "12:30:08"; 现在要删掉冒号,变成123008 就可以先split var splitFirst = Str ...

  10. bzoj1644 / P1649 [USACO07OCT]障碍路线Obstacle Course

    P1649 [USACO07OCT]障碍路线Obstacle Course bfs 直接上个bfs 注意luogu的题目和bzoj有不同(bzoj保证有解,还有输入格式不同). #include< ...