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 ...
随机推荐
- linux下查找字符串
如果你想在当前目录下 查找"hello,world!"字符串,可以这样: grep -rn "hello,world!" * * : 表示当前目录所有文件,也可 ...
- view 状态动画
stateListAnimator 一.xml配置 方法 res/xml/animate_scale.xml <?xml version="1.0" encoding=&qu ...
- 【Node.js】一个愚蠢的Try Catch过错
前段时间学习<深入浅出Nodejs>时,在第四章 - 异步编程中作者朴灵曾提到,异步编程的难点之一是异常处理,书中描述"尝试对异步方法进行try/catch操作只能捕获当次事件循 ...
- java设置随机数教程
java作为程序猿开发人员都在使用的一款编程语言,许多入门的朋友都陷入了一个简单的问题就是,使用java开发时随机数要怎么设置?java怎么设置随机数?经常会有地方需要用到随机数,不用着急,一起来看看 ...
- Django基础--2
一.路由系统 URL 1.模板语言循环字典 1.简单的字典循环 <ul> {% for i in user_dict %} <li>{{ i }}</li> {% ...
- js call(),apply(),对象冒充,改变变量作用域
1.apply(); function box(n1,n2){ return n1+n2; } function pox(n1,n2){ alert(box.apply(this,[n1,n2])); ...
- Locust的官网及安装
Locust官网: https://docs.locust.io/en/latest/installation.html for Python 3: $ python3 -m pip install ...
- IOS Post请求(请求服务器)
@interface HMViewController () @property (weak, nonatomic) IBOutlet UITextField *usernameField; @pro ...
- window/win7/wamp下安装Xdebug
1.写一个php文件,输出phpinfo(); 然后把该页面Ctrl+A全选,然后贴到http://xdebug.org/wizard.php这个地址的文本框里,他会自动检查你的配置,然后告诉你用哪个 ...
- 2018.8.25 JVM
一.JVM内存区域 Java虚拟机在运行时,会把内存空间分为若干个区域,根据<Java虚拟机规范(Java SE 7 版)>的规定,Java虚拟机所管理的内存区域分为如下部分: 方法区 堆 ...