Showstopper [POJ3484] [二分] [思维]
Description
给你n个数列,问哪一个数字在所有的数列中出现了奇数次(最多一个)。
Sample Input
1 10 1
2 10 1 1 10 1
1 10 1 1 10 1
4 4 1
1 5 1
6 10 1
Sample Output
1 1
no corruption
4 3
Analysis
我们假装按大小排好了每个数,然后我们发现,如果统计每个数出现的次数,要求的数X是奇数,其他的是偶数,那么记录前缀和,X之前全为偶数(偶+偶+...+偶=偶),X及X以后都是奇数(奇+偶=奇),那我们就可以按照这个规律二分了。
这道题还是蛮有意思的,如果奇数和偶数对掉的话,这道题就不可做了。
Code
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b) for(RG i=a;i<=b;++i)
#define per(i,a,b) for(RG i=a;i>=b;--i)
#define ll long long
#define inf 0x8f8f8f8f8f
#define maxn 100005
using namespace std;
ll X[maxn],Y[maxn],Z[maxn],cnt;
char s[maxn];
inline int read()
{
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int judge(ll lim)
{
ll sum=;
rep(i,,cnt)
{
if(lim<X[i]) continue;
sum+=(min(Y[i],lim)-X[i])/Z[i]+;
}
return sum&;
} ll cal(ll lim)
{
ll sum=;
rep(i,,cnt)
{
if(lim<X[i]) continue;
sum+=(min(Y[i],lim)-X[i])/Z[i]+;
}
return sum;
} void work()
{
ll l=,r=inf,mid,ans=-;
while(l<=r)
{
mid=(l+r)>>;
if(judge(mid)) ans=mid,r=mid-;
else l=mid+;
}
if(ans==-) puts("no corruption");
else
{
printf("%lld %lld\n",ans,cal(ans)-cal(ans-));
}
} int main()
{
while(gets(s)!=NULL)
{
if(!strlen(s))
{
if(!cnt) continue;
work();cnt=;
}
else
{
++cnt;
sscanf(s,"%lld %lld %lld",&X[cnt],&Y[cnt],&Z[cnt]);
}
}
if(cnt) work();
return ;
}
Showstopper [POJ3484] [二分] [思维]的更多相关文章
- Atcoder Grand Contest 006 D - Median Pyramid Hard(二分+思维)
Atcoder 题面传送门 & 洛谷题面传送门 u1s1 Atcoder 不少思维题是真的想不出来,尽管在 Atcoder 上难度并不高 二分答案(这我倒是想到了),检验最上面一层的数是否 \ ...
- POJ 3484 Showstopper(二分答案)
[题目链接] http://poj.org/problem?id=3484 [题目大意] 给出n个等差数列的首项末项和公差.求在数列中出现奇数次的数.题目保证至多只有一个数符合要求. [题解] 因为只 ...
- codeforces 895B XK Segments 二分 思维
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...
- cf1153E 二分思维交互
恶臭的交互题 /* 一个结论:一个矩形将空间分割成两部分,如果开头结尾都在一个部分内,那么穿过矩形边框的线条数就是偶数,反之就是奇数 通过这个结论来进行判断 先询问999次将两个x坐标确定,方法是询问 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- BZOJ - 5427:最长上升子序列 (二分&思维)
现在给你一个长度为n的整数序列,其中有一些数已经模糊不清了,现在请你任意确定这些整数的值, 使得最长上升子序列最长.(为何最长呢?因为hxy向来对自己的rp很有信心) Input 第一行一个正整数 ...
- codeforces 985 D. Sand Fortress(二分+思维)
Sand Fortress time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- codeforces E. Mahmoud and Ehab and the function(二分+思维)
题目链接:http://codeforces.com/contest/862/problem/E 题解:水题显然利用前缀和考虑一下然后就是二分b的和与-ans_a最近的数(ans_a表示a的前缀和(奇 ...
- codeforces 814 C. An impassioned circulation of affection(二分+思维)
题目链接:http://codeforces.com/contest/814/problem/C 题意:给出一串字符串然后q个询问,问替换掉将m个字符替换为字符c,能得到的最长的连续的字符c是多长 题 ...
随机推荐
- JS输入框统计文字数量
$('#articleTitle').bind('input propertychange',function () { var a = $(this).val().length; if(a>3 ...
- es6编程建议和技巧点汇总
大括号 特点:大括号(单独的大括号或者if等后的大括号)内是一个单独的作用域 注意点:在块级作用域内声明的函数,类似var,会被提升到大括号外,应避免在块级作用域内声明函数.如果确实需要,写成函数表达 ...
- smartgit
1.同步最新分支 2.smartgit ctrl+2 可以看到本地新增加的文件
- torch.utils.data.DataLoader对象中的迭代操作
关于迭代器等概念参考:https://www.cnblogs.com/zf-blog/p/10613533.html 关于pytorch中的DataLoader类参考:https://blog.csd ...
- python的一些基本概念
1.为什么python被称为胶水语言?他是新一代的系统脚本参考博客:https://www.cnblogs.com/ningskyer/articles/5264172.html 2.python百度 ...
- Python-Django 模型层-单表查询
单表操作 -增加,删,改:两种方式:queryset对象的方法,book对象的方法 -改:需要用save() -get()方法:查询的数据有且只有一条,如果多,少,都抛异常 单表查询 -<1&g ...
- @Transactional 无效原因
在controller 上面使用 @Transactional 注解时候发现数据没有回滚,在执行完update 更新语句,事务直接就commit 了, 此时方法尚未执行结束,数据库数据已经更新了. ...
- Scapy
1.UDP scanning with Scapy Scapy is a tool that can be used to craft and inject custom packets into ...
- select2 下拉搜索控件
1.添加相应的script链接 jquery: <script type="text/javascript" src="http://cdn.bootcss.com ...
- Linux安装与基本命令
安装centos镜像 #下载地址https://www.centos.org/download/ http://isoredirect.centos.org/centos/7/isos/x86_64/ ...