POJ 3484 二分
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
Source
//#include"bits/stdc++.h"
#include<sstream>
#include<iomanip>
#include"cstdio"
#include"map"
#include"set"
#include"cmath"
#include"queue"
#include"vector"
#include"string"
#include"cstring"
#include"time.h"
#include"iostream"
#include"stdlib.h"
#include"algorithm"
#define db double
#define ll long long
#define vec vector<ll>
#define mt vector<vec>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
//#define rep(i, x, y) for(int i=x;i<=y;i++)
#define rep(i, n) for(int i=0;i<n;i++)
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = mod - ;
const int inf = 0x3f3f3f3f;
const db PI = acos(-1.0);
const db eps = 1e-;
using namespace std;
ll x[N],y[N],z[N],cnt=;
char s[N];
ll cal(ll k)
{
ll ans=;
for(int i=;i<cnt;i++){
if(k<x[i]) continue;
ans+=(min(y[i],k)-x[i])/z[i]+;//统计小于等于k的数有多少个
}
return ans;
}
ll solve()
{
ll l=-,r=(1ll<<),ans=-;
while(l<=r)
{
ll mid=(l+r)/;
if(cal(mid)%==) r=mid-,ans=mid;//若为奇数个则目标数字x<=mid
else l=mid+;//否则目标数字x>mid
}
return ans;
}
int main()
{
cnt=;
while(gets(s)!=NULL){
if(strlen(s)==)
{
if(!cnt) continue;
ll ret=solve();
if(ret==-) puts("no corruption");
else printf("%lld %lld\n",ret,cal(ret)-cal(ret-));
cnt=;
}
else
{
sscanf(s,"%lld%lld%lld",&x[cnt],&y[cnt],&z[cnt]);//必须用sscanf?
cnt++;
}
}
if(cnt)
{
ll ret=solve();
if(ret==-) puts("no corruption");
else printf("%lld %lld\n",ret,cal(ret)-cal(ret-));
}
return ;
}
POJ 3484 二分的更多相关文章
- POJ - 2018 二分+单调子段和
依然是学习分析方法的一道题 求一个长度为n的序列中的一个平均值最大且长度不小于L的子段,输出最大平均值 最值问题可二分,从而转变为判定性问题:是否存在长度大于等于L且平均值大于等于mid的字段和 每个 ...
- POJ 3484 Showstopper(二分答案)
[题目链接] http://poj.org/problem?id=3484 [题目大意] 给出n个等差数列的首项末项和公差.求在数列中出现奇数次的数.题目保证至多只有一个数符合要求. [题解] 因为只 ...
- poj 3621 二分+spfa判负环
http://poj.org/problem?id=3621 求一个环的{点权和}除以{边权和},使得那个环在所有环中{点权和}除以{边权和}最大. 0/1整数划分问题 令在一个环里,点权为v[i], ...
- POJ 3061 (二分+前缀和or尺取法)
题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...
- POJ 2456 (二分)
题目链接: http://poj.org/problem?id=2456 题目大意:n个房子,m头牛,房子有一个横坐标,问将m头牛塞进房子,每两头牛之间的最大间隔是多少. 解题思路: 不难看出应该二分 ...
- POJ 1064 (二分)
题目链接: http://poj.org/problem?id=1064 题目大意:一堆棍子可以截取,问要求最后给出K根等长棍子,求每根棍子的最大长度.保留2位小数.如果小于0.01,则输出0.00 ...
- poj 3228(二分+最大流)
题目链接:http://poj.org/problem?id=3228 思路:增设一个超级源点和一个超级汇点,源点与每一个gold相连,容量为gold数量,汇点与仓库相连,容量为仓库的容量,然后就是二 ...
- poj 3685 二分
Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 7415 Accepted: 2197 Descriptio ...
- POJ 3579 二分
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7687 Accepted: 2637 Descriptio ...
随机推荐
- Sass基础(一)
一.Sass语法规范 1.Sass老版本:通过tab键严格控制缩进:不带有任何分号和大括号:以“.sass”为扩展名. 2.Sass新语法格式(Scss):外形和css无差,以“.scss”为扩展名. ...
- position的参考基准
static(静态):position默认的样式:占据标准流的位置, 它会忽略top.bottom.left . right 的设置 relative(相对): 占据标准流的位置:可将其移至相对于其正 ...
- Vue.js - Day2
品牌管理案例 添加新品牌 删除品牌 根据条件筛选品牌 1.x 版本中的filterBy指令,在2.x中已经被废除: filterBy - 指令 <tr v-for="item in ...
- BZOJ3261: 最大异或和(可持久化trie树)
题意 题目链接 Sol 设\(sum[i]\)表示\(1 - i\)的异或和 首先把每个询问的\(x \oplus sum[n]\)就变成了询问前缀最大值 可持久化Trie树维护前缀xor,建树的时候 ...
- [MedicalEndoscope]PFC介绍
PFC的英文全称为“Power Factor Correction”,意思是“功率因数校正”,功率因数指的是有效功率与总耗电量(视在功率)之间的关系,也就是有效功率除以总耗电量(视在功率)的比值. 基 ...
- traffic_light_bag_file 数据集 下载链接
链接:https://pan.baidu.com/s/19p5aGRfs6iFtN_SWAxCkRQ 密码:v9wx
- 解方程求PH值,POJ(2006)
题目链接:http://poj.org/problem?id=2006 解题报告: 题意看了半天,没看懂,再加上化学没学好,更加让我头痛. 假设1L溶解了x摩尔的酸:ka=m*x*nx/ori-x; ...
- linux命令之sed命令
sed是一种流编辑器,它是文本处理中非常中的工具,能够完美的配合正则表达式使用,功能不同凡响.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令 ...
- dotNetFx40_Client_x86_x64和dotNetFx40_Full_x86_x64这两个有什么区别?两个都要安装还是安装其中一个?
这个是NET Framework 4.0的安装文件它是支持生成和运行下一代应用程序和 XML Web Services 的内部 Windows 组件,很多基于此架构的程序需要它的支持才能够运行.简单的 ...
- 楔积(Wedge Procut)
原文链接 由拓扑学中表面(Surface)的定义及实例引入楔积的概念. 基础知识 先看Surface在欧几里得空间内的定义: 所有在Omega中的点w(参数空间中的点)被记作: 对应在R3中(欧几里德 ...