POJ 3484 Showstopper(二分答案)
【题目链接】 http://poj.org/problem?id=3484
【题目大意】
给出n个等差数列的首项末项和公差。求在数列中出现奇数次的数。题目保证至多只有一个数符合要求。
【题解】
因为只有一个数符合要求,所以在数列中数出现次数的前缀和必定有奇偶分界线,
所以我们二分答案,计算前缀和的奇偶性进行判断,得到该数的位置。
【代码】
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=500010;
const LL inf=1LL<<33;
LL X[N],Y[N],Z[N];
char s[60];
int n;
LL cal(LL x){
LL ans=0,t;
for(int i=1;i<=n;i++){
if(x<X[i])continue;
t=min(x,Y[i]);
ans+=(t-X[i])/Z[i]+1;
}return ans;
}
int main(){
while(gets(s)){
X[n=1]=0;
sscanf(s,"%lld %lld %lld",&X[n],&Y[n],&Z[n]);
if(!X[n])continue;
memset(s,0,sizeof(s));
while(gets(s),*s)n++,sscanf(s,"%lld %lld %lld",&X[n],&Y[n],&Z[n]),memset(s,0,sizeof(s));
LL l=1,r=inf,ans=0;
while(l<=r){
LL mid=(l+r)>>1;
if(cal(mid)&1LL)r=mid-1,ans=mid;
else l=mid+1;
}if(!ans)puts("no corruption");
else printf("%lld %lld\n",ans,cal(ans)-cal(ans-1));
}return 0;
}
POJ 3484 Showstopper(二分答案)的更多相关文章
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- poj 3484 Showstopper
Showstopper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2236 Accepted: 662 Descri ...
- POJ 3122 Pie 二分答案
题意:给你n个派,每个派都是高为一的圆柱体,把它等分成f份,每份的最大体积是多少. 思路: 明显的二分答案题-- 注意π的取值- 3.14159265359 这样才能AC,,, //By Sirius ...
- POJ Building roads [二分答案 2SAT]
睡觉啦 #include <iostream> #include <cstdio> #include <cstring> #include <algorith ...
- Poj 1743 Musical Theme(后缀数组+二分答案)
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 Descri ...
- 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774
Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...
- POJ 1064 Cable master (二分答案)
题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...
- POJ 3662 Telephone Lines(二分答案+SPFA)
[题目链接] http://poj.org/problem?id=3662 [题目大意] 给出点,给出两点之间连线的长度,有k次免费连线, 要求从起点连到终点,所用的费用为免费连线外的最长的长度. 求 ...
- POJ 3579 Median(二分答案+Two pointers)
[题目链接] http://poj.org/problem?id=3579 [题目大意] 给出一个数列,求两两差值绝对值的中位数. [题解] 因为如果直接计算中位数的话,数量过于庞大,难以有效计算, ...
随机推荐
- python之列表、字典的使用
一.概述:以后你在Linux里面写Python脚本的时候会经常用到Python列表.字典,因为你在以后写脚本的时候,大多数情况下都是对文件进行操作处理,使用字典和列表可以很好的操作文件,得出你想要的结 ...
- Centos7网络配置+图形界面设置
一. 查看网络地址: centos7取消了ifconfig命令,使用ip addr命令查看IP地址 二.配置网络 用VirtualBox安装的CentOS7,安装完成后,发现无法上网,于是到网上查了一 ...
- 杭电oj 3079 Vowel Counting
Tips:可以先将输入的字符串全部转化为小写字母,然后再将元音字母变为大写,时间复杂度O(n) #include<stdio.h> #include<string.h> #in ...
- 云脉表格识别开放SDK接入
通过深度的引擎识别和文本处理技术给予表单提供了无与伦比的文档分析和数据的提取功能,云脉表单识别包含了先进的模板学习和文本.图像分析提取技术,通过模板元素定义表单,将整个南表单生命周期和生产数据以自动化 ...
- python安装完毕后,提示找不到ssl模块的解决方示
python安装完毕后,提示找不到ssl模块: [root@localhost ~]# python2.7.5 Python 2.7.5 (default, Jun 3 2013, 11:08:43) ...
- 使用ashx一般处理程序,读取不到Session的问题
一般的处理程序文件里面是用不了Session的,必须得实现Session接口才可以用. public class RandomCode : IHttpHandler, System.Web.Sessi ...
- how to translate the text of push button
Background:In a project, the need to translate the buttons on the screen, as shown below,the followi ...
- paip.navicat form mysql导入文本文件时CPU占用100%的解决
paip.navicat form mysql导入文本文件时CPU占用100%的解决 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:h ...
- 【拓扑排序】【HDU3231】【Box Relations】
题目大意: N个盒子 给你K个以下关系 1.A和B有重叠 2.A在B的左边且不重叠 3.A在B的前边且不重叠 4.A在B的上面且不重叠 显然单独分配X坐标处理2(x1<x2<x1'< ...
- 编写isNull isArray isFunction的方法
1.isNull 判断null,需要排除掉undefined和0.''(空串). function isNull(arr){ return !arr&&typeof arr!=='un ...