Poj3484-Showstopper(二分脑洞题)
Description
Data-mining huge data sets can be a painful and long lasting process if we are not aware of tiny patterns existing within those data sets.
One reputable company has recently discovered a tiny bug in their hardware video processing solution and they are trying to create software workaround. To achieve maximum performance they use their chips in pairs and all data objects in memory should have even number of references. Under certain circumstances this rule became violated and exactly one data object is referred by odd number of references. They are ready to launch product and this is the only showstopper they have. They need YOU to help them resolve this critical issue in most efficient way.
Can you help them?
Input
Input file consists from multiple data sets separated by one or more empty lines.
Each data set represents a sequence of 32-bit (positive) integers (references) which are stored in compressed way.
Each line of input set consists from three single space separated 32-bit (positive) integers X Y Z and they represent following sequence of references: X, X+Z, X+2*Z, X+3*Z, …, X+K*Z, …(while (X+K*Z)<=Y).
Your task is to data-mine input data and for each set determine weather data were corrupted, which reference is occurring odd number of times, and count that reference.
Output
For each input data set you should print to standard output new line of text with either “no corruption” (low case) or two integers separated by single space (first one is reference that occurs odd number of times and second one is count of that reference).
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 题意:每组测试样例会给出多组X,Y,Z的值,代表X,X+Z,X+2*Z....X+k*Z(X+k*Z<=Y)这些值会出现一次。然后题目保证所有出现的数的次数要么全是偶数个,要么只有一个数的次数是奇数个,
如果都是偶数个,则输出no corruption,否则输出这个数以及出现的次数。 解析:这题X,Y,Z的值这么大,显然不可能枚举,请注意题目给的条件,仔细想想后,可以用二分来做,先判断所有出现的数的次数之和是否是偶数,如果是,直接输出no corruption,因为是
偶数的话不可能出现某个数出现的次数是奇数的。然后再二分,计算小于等于mid的所有数出现的次数,如果为偶数则向大的走,否则向小的走(仔细思考一下就能明白)。还有这道题的输入比较
坑,注意一下。 代码
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<utility>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iterator>
#include<stack>
using namespace std;
typedef __int64 LL;
const LL INF=1e10+;
const double eps=1e-;
const int maxn=;
int N;
struct node
{
LL x,y,z;
node(LL x=,LL y=,LL z=):x(x),y(y),z(z){}
}nod[maxn];
bool judge(LL mid)
{
LL ret=;
for(int i=;i<N;i++)
{
node& t=nod[i];
LL x=t.x,y=t.y,z=t.z;
if(mid<x) continue;
LL a=min(y,mid);
ret+=(a-x)/z+;
}
return ret%==;
}
LL Cal(LL v)
{
LL ret=;
for(int i=;i<N;i++)
{
node& t=nod[i];
LL x=t.x,y=t.y,z=t.z;
if(v<x||v>y) continue;
if((v-x)%z==) ret++;
}
return ret;
}
void solve()
{
LL ret=;
for(int i=;i<N;i++) //计算整个值
{
node& t=nod[i];
LL x=t.x,y=t.y,z=t.z;
ret+=(y-x)/z+;
}
if(ret%==){ cout<<"no corruption"<<endl; return; } //为偶数
LL low=,up=INF,mid;
while(true)
{
if(low==up) break;
mid=(low+up)/;
if(judge(mid)) low=mid+; //二分
else up=mid;
}
printf("%I64d %I64d\n",low,Cal(low));
}
int main()
{
char S[];
bool err=false;
while(true)
{
N=;
while(true)
{
if(gets(S)==NULL) return ;
if(strlen(S)==) continue;
break;
}
LL x,y,z;
string s="";
for(int i=;S[i]!='\0';i++) s+=S[i];
istringstream out(s);//字符串输入流
out>>x>>y>>z;
if(x<=y) nod[N++]=node(x,y,z);
while(true)
{
if(gets(S)==NULL) {err=true; break; }
if(strlen(S)==) break;
string s="";
for(int i=;S[i]!='\0';i++) s+=S[i];
istringstream out(s);
out>>x>>y>>z;
if(x<=y) nod[N++]=node(x,y,z);
}
solve();
if(err) break;
}
return ;
}
Poj3484-Showstopper(二分脑洞题)的更多相关文章
- POJ3484 Showstopper (二分+字符串处理)
POJ3484 Showstopper 题目大意: 每次给出三个数x,y,z,用这三个数构成一个等差数列,x为首项,y是末项,z是公差 总共给出n组x,y,z( n待定),求这n组数列中出现次数为奇数 ...
- poj3484 Showstopper 二分
题目地址 二分用的很是巧妙!关键是抽象出问题本质. #include <cstdio> #include <string> #include <cstring> ; ...
- 图论(KM算法,脑洞题):HNOI 2014 画框(frame)
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABPoAAANFCAIAAABtIwXVAAAgAElEQVR4nOydeVxTV/r/n9ertaJEC4
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- AT2165 Median Pyramid Hard 二分答案 脑洞题
无论再来多少次也不可能想到的写法. 二分一个最小的顶端值\(k\),大于设为\(1\)小于等于设为\(0\),可以证猜出来(你跟我说这可以?)如果存在两个连在一起的0/1那么它们会一直往上跑,还可以很 ...
- HDU 2199 Can you solve this equation? (二分 水题)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- SCU 4527 NightMare2 最短路+二分 好题
可怜的又做噩梦了..但是这次跟上次不大一样,虽然他又被困在迷宫里,又被装上了一个定时炸弹,但是值得高兴的是,他发现他身边有数不清的财宝,所以他如果能带着这些财宝并活着逃出去的话,他就发财啦.不过,这次 ...
- 51nod 1105 二分好题
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1105 1105 第K大的数 基准时间限制:1 秒 空间限制:131072 ...
- luoguP4343自动刷题机(二分标准题)
https://www.luogu.org/problem/P4343 参考博客:https://www.luogu.org/blog/ofnoname/solution-p4343 这真是一语点醒梦 ...
随机推荐
- hdu1540-Tunnel Warfare (线段树区间合并)
题意:n个村庄,有三种操作,D x 破坏位置为x的村庄,R 修复上一次被破坏的村庄,Q x 输出含有x村庄的连续村庄的最大个数.线段树搞之,区间合并. ls[maxn]为当前节点左面的连续区间,rs[ ...
- 深入super,看Python如何解决钻石继承难题
1. Python的继承以及调用父类成员 python子类调用父类成员有2种方法,分别是普通方法和super方法 假设Base是基类 class Base(object): def __init_ ...
- apache2 httpd 基于域名的虚拟主机配置 for centos6X 和debian-8
全系统虚拟主机: for debian 系统的apache2 域名 虚拟主机
- Swift字符串常用操作总结
转自:http://www.jianshu.com/p/52e7580166ff 1.string转换为Int/Long/Float/Double/Bool等 var str1="100&q ...
- python3-day5(模块)
1.获取路径import os,sys #获取全部路径 print(os.path.abspath(__file__)) #获取目录 print(os.path.dirname(os.path.abs ...
- JavaScript 判断一个字符串是否在另一个字符串中
传统上,JavaScript只有indexOf方法,可以用来确定一个字符串是否包含在另一个字符串中.ES6又提供了三种新方法. includes():返回布尔值,表示是否找到了参数字符串. start ...
- [置顶] iOS 应用程序内部国际化,不跟随系统语言
前言:网络上关于iOS国际化的文章很多,但基本上都是基于跟随系统语言的国际化,笔者就不赘述了-0 – 今天要讲的是不跟随系统的切换语言版本方案,即程序内部的切换语言版本方案. 一.总则: 应用内部语言 ...
- Java之面向对象相关问题集
面向对象的特征有哪些方面 1.抽象: 抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解所有问题,而仅仅是选择当中的一部分,临时不用部分细节. 抽 ...
- 退役笔记一#MySQL = lambda sql : sql + ' Source Code 4 Explain Plan '
Mysql 查询运行过程 大致分为4个阶段吧: 语法分析(sql_parse.cc<词法分析, 语法分析, 语义检查 >) >>sql_resolver.cc # JOIN.p ...
- 杭电 HDU ACM Milk
Milk Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...