poj 3484 Showstopper(二分)
来源:互联网 发布:me452ch a是什么网络 编辑:程序博客网 时间:2024/06/18 09:49
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 12 10 11 10 11 10 11 10 14 4 11 5 16 10 1
Sample Output
1 1no corruption4 3
题意:给你多个等差数列公差,首项和最大范围,求出哪个数出现奇数次。
分析:我们把某个数之前所有数出现过的总次数求出来,会发现会呈现偶偶偶偶偶偶偶偶偶奇奇奇奇奇奇奇奇的现象。
然后二分查询。提醒:每组数据之间可能会有多空行。
代码;
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <stack>#include <map>#include <set>#include <vector>#include <queue>#define mem(p,k) memset(p,k,sizeof(p));#define rep(i,j,k) for(int i=j; i<k; i++)#define pb push_back#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define inf 0x6fffffff#define ll long longusing namespace std;const int mod=1e9+7;int n,m,k,cur,x,y;ll minn,maxx;int nex[4][2]={0,1,1,0,0,-1,-1,0};char str[500000];ll a[110000],b[110000],c[110000];int jud(ll m,int len){ ll sum=0; for(int i=0;i<len;i++){ if(m<a[i])continue; ll k=min(m,b[i]); //cout<<(k-a[i]+1)/c[i]<<endl; sum+=(k-a[i])/c[i]+1; } //cout<<m<<"=="<<sum<<endl; if(sum&1)return 1; return 0;}void solve(int len){ ll l=1,r=maxx; while(l<=r){ ll m=(l+r)>>1;//cout<<l<<"==="<<r<<endl; if(jud(m,len)){ r=m-1; } else l=m+1; } if(l>maxx)cout<<"no corruption"<<endl; else{ ll sum=0; for(int i=0;i<len;i++){ if(l>=a[i]&&l<=b[i]){ if((l-a[i])%c[i]==0){ sum++; }//cout<<sum<<endl; } } cout<<l<<" "<<sum<<endl; } return ;}int main(){ int le=0; maxx=0x9fffffff; while(gets(str)){ if(strlen(str)==0){ if(le==0)continue; solve(le); le=0; maxx=0x9fffffff; continue; } sscanf(str,"%I64d%I64d%I64d",a+le,b+le,c+le); le++; } if(le){ solve(le); } return 0;}
- poj 3484 Showstopper(二分)
- Showstopper - POJ 3484 二分
- POJ 3484 Showstopper 二分
- Showstopper - POJ 3484 二分
- POJ 3484 Showstopper (二分搜索)
- POJ 3484 - Showstopper(二分搜索)
- POJ - 3484 Showstopper 二分搜索
- POJ - 3484 Showstopper(二分 + 前缀和)
- POJ3484 Showstopper(二分)
- POJ 3484 Showstopper
- POJ-3484-Showstopper
- POJ 3484 Showstopper 已翻译
- poj3484 Showstopper 二分
- 【BZOJ1243】[Seerc2007]Showstopper【二分】
- POJ 3484(规律+二分)
- poj 3273 (二分)
- poj 3122(二分)
- poj 1905(二分)
- RecyclerView简单使用总结
- 比较二棵二叉排序树是否相等
- JDK1.6在SUSE11下问题跳变定时任务失效问题记录
- 51nod 1056 最长等差数列 V2
- Oracle-分析函数之sum(...) over(...)
- poj 3484 Showstopper(二分)
- iOS自定义摄像机或者拍照
- Couldn't run /usr/bin/dumpcap in child process:权限不够
- python中的os.path.join() 作用
- Anbox让你在Linux上“原生运行”Android应用
- Python进阶(三十五)-Fiddler命令行和HTTP断点调试
- android中常用的弹出提示框
- 基于deepinlinux的manjarolinux 多了不少好用的软件
- PHP 日期时间 获取服务器当前时间、日期 全解析