【CF】283D Tennis Game
枚举t加二分判断当前t是否可行,同时求出s。
注意不能说|a[n]| <= |3-a[n]|就证明无解,开始就是wa在这儿了。
可以简单想象成每当a[n]赢的时候,两人都打的难解难分(仅多赢一轮);而每当a[n]输的时候,一轮都没赢。
在这个前提下,显然存在|a[n]| <= |3-a[n]|。
/* 283D */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const int maxn = 1e5+;
int a[maxn];
int cnt[][maxn];
int n;
int id; int calc(int t) {
int i, j, p, q;
int c[];
int b[]; b[] = b[] = ;
c[] = c[] = ;
p = ;
while () {
i = lower_bound(cnt[]+p, cnt[]++n, c[]+t) - (cnt[]);
j = lower_bound(cnt[]+p, cnt[]++n, c[]+t) - (cnt[]);
if (cnt[][i]-c[]!=t && cnt[][j]-c[]!=t)
return ;
if (i < j) {
// 1 win
q = ;
++b[];
p = i;
} else {
q = ;
++b[];
p = j;
}
c[] = cnt[][p];
c[] = cnt[][p];
if (p >= n)
break;
} if (p != n)
return ; int id_ = - id;
if (b[id_]>=b[id] || q!=id)
return ;
return b[id];
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int c[]; scanf("%d", &n);
c[] = c[] = ;
rep(i, , n+) {
scanf("%d", &a[i]);
++c[a[i]];
cnt[a[i]][i] = cnt[a[i]][i-] + ;
cnt[-a[i]][i] = cnt[-a[i]][i-];
}
cnt[][n+] = cnt[][n+] = INT_MAX; id = a[n];
int an = c[id], bn = c[]+c[]-an; // if (an <= bn) {
// puts("0");
// return 0;
// } int i, j;
vpii ans; for (i=; i<=n; ++i) {
j = calc(i);
if (j)
ans.pb(mp(j, i));
} sort(all(ans)); n = SZ(ans);
printf("%d\n", n);
rep(i, , n) {
printf("%d %d\n", ans[i].fir, ans[i].sec);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【CF】283D Tennis Game的更多相关文章
- 【CF】438E. The Child and Binary Tree
http://codeforces.com/contest/438/problem/E 题意:询问每个点权值在 $c_1, c_2, ..., c_m$ 中,总权值和为 $s$ 的二叉树个数.请给出每 ...
- 【CF】148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...
- 【CF】328 D. Super M
这种图论题已经变得简单了... /* D */ #include <iostream> #include <string> #include <map> #incl ...
- 【CF】323 Div2. D. Once Again...
挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...
- 【CF】7 Beta Round D. Palindrome Degree
manacher+dp.其实理解manacher就可以解了,大水题,dp就是dp[i]=dp[i>>1]+1如何满足k-palindrome条件. /* 7D */ #include &l ...
- 【CF】86 B. Petr#
误以为是求满足条件的substring总数(解法是KMP分别以Sbeg和Send作为模式串求解满足条件的position,然后O(n^2)或者O(nlgn)求解).后来发现是求set(all vali ...
- 【CF】121 Div.1 C. Fools and Roads
题意是给定一棵树.同时,给定如下k个查询: 给出任意两点u,v,对u到v的路径所经过的边进行加计数. k个查询后,分别输出各边的计数之和. 思路利用LCA,对cnt[u]++, cnt[v]++,并对 ...
- 【CF】310 Div.1 C. Case of Chocolate
线段树的简单题目,做一个离散化,O(lgn)可以找到id.RE了一晚上,额,后来找到了原因. /* 555C */ #include <iostream> #include <str ...
- 【CF】110 Div.1 B. Suspects
这题目乍眼一看还以为是2-sat.其实很水的,O(n)就解了.枚举每个人,假设其作为凶手.观察是否满足条件.然后再对满足的数目分类讨论,进行求解. /* 156B */ #include <io ...
随机推荐
- ACM——圆柱体的表面积
lems 1092 圆柱体的表面积 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2697 测试通过:414 ...
- eclipse Ctrl+1 没反应
今天上午写代码,突然发现Ctrl+1没反应了,顿时无语.昨天还好好的,今天就不行了…… 无奈,只好在网上查了查,据说快捷键冲突的原因比较大. 于是我将Ctrl+1换成了Alt+1.在eclipse中测 ...
- 状态栏通知Notification的简单使用
今天在学习Notification时同时参考了一些相关的博客,现在结合自身学习实际来总结一下. 在使用手机时,当有未接来电或者短消息时,通常会在手机屏幕上的状态栏上显示.而在Android中有提醒功能 ...
- html中可以使用在块级元素<body>中的元素
1.<p></p>当在html页面中需要显示大段文字的时候,可以使用p元素标记每一个段落的边界,需要注意的是,段落是块级元素,只允许包含文本和行内元素. 以下标注的是p中的标准 ...
- news总结
上回的因为停网所以无法上传,被我保存成了一个我不会打开的东西,没法用了. news:新闻发布系统. 完成状态:差 个人理解度:一知半解 总结目的:秘密 直到现在,我对整个练习的知识点上的理解都不是很好 ...
- struts 文件上传下载
上传 1.编写上传action类 UploadAction.java package jxf.b_upload; import java.io.File; import java.io.IOExcep ...
- JavaWeb网上商城的反思
不知道从什么时候起,我爱上了写博客,对之前学得的只是进行反思.写了几天课程设计,代码量量8.9千左右. 然后下面文字是我在博客上复制过来的,说得很详细 MVC(Model View Controlle ...
- C# 时间与时间戳互转
/// <summary> /// 将c# DateTime时间格式转换为Unix时间戳格式 /// </summary> /// <param name="t ...
- jquery中的 .html(),.val().text()
.html(),.text(),.val(),.html()用为读取和修改元素的HTML标签,包括标签内的内容.text()用来读取或修改元素的纯文本内容,去除 html 标签.val()用来读取或修 ...
- jquery阻止事件的两种实现方式
再阻止事件冒泡的方面,jquery有两种方式: 一种是 return false;另外一种是 e.stopPropagation() html代码 <form id="form1&qu ...