codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)
题意:网球有一方赢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)的更多相关文章
- 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns
题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- 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 ...
- Codeforces Round #283 Div.2 D Tennis Game --二分
题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛.求有多少种 t 和 s 的分配方案并输出t,s. 解法: 因为要知道 ...
- 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 ...
- 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 ...
- Codeforces Round #283 (Div. 2)
A:暴力弄就好,怎么方便怎么来. B:我们知道最多加10次, 然后每次加1后我们求能移动的最小值,大概O(N)的效率. #include<bits/stdc++.h> using name ...
- codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)
题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...
- 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 ...
随机推荐
- [備註] 安裝與整合 xUnit 測試框架@VS2012
開發環境:Visual Studio 2012, Update 1 (必須). 說明:VS2012 已整合各測試框架的 Test Runner,包括 NUnit, xUnit 等.藉由標準的介面,可讓 ...
- 基于Axis1.4的webservice接口开发(环境搭建)
基于Axis1.4的webservice接口开发(环境搭建) 一.环境搭建: 1.搜索关键字“Axis1.4”下载Axis1.4相关的jar包. 下载地址:http://download.csdn.n ...
- python 简单的爬虫
import urllib.request import re import ssl # 处理https请求 import time import os # 创建目录用 def get_html(ur ...
- MySQL性能分析和优化
1. EXPLAIN 优化你的 SELECT 查询 2. 当只要一行数据时使用 LIMIT 1 3. 为搜索字段建索引 like %最好放右边 4. 尽可能的使用 NOT NULL 5. 在Join表 ...
- Nginx服务器之负载均衡策略(6种)
一.关于Nginx的负载均衡 在服务器集群中,Nginx起到一个代理服务器的角色(即反向代理),为了避免单独一个服务器压力过大,将来自用户的请求转发给不同的服务器.详情请查看我的另一篇博客. 二.Ng ...
- python-kafka之理论篇
kafka系列文章之python-api的使用. 在使用kafka-python时候需要注意,一定要版本兼容,否则在使用生产者会报 无法更新元数据的错误. 在本片测试中java版本为如下,kafka版 ...
- adb shell 命令详解,android, adb logcat
http://www.miui.com/article-275-1.html http://noobjava.iteye.com/blog/1914348 adb shell 命令详解,android ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- 20145206邹京儒 web安全基础实践
20145206邹京儒 web安全基础实践 一.实践过程记录 关于WebGoat 1.我们在命令行里执行:java -jar webgoat-container-7.0.1-war-exec.jar运 ...
- 常用模块之 shutil,json,pickle,shelve,xml,configparser
shutil 高级的文件.文件夹.压缩包 处理模块 shutil.copyfileobj(fsrc, fdst[, length]) 将文件内容拷贝到另一个文件中 import shutil shut ...