POJ-3484 Showstopper---二分+前缀和
题目链接:
https://cn.vjudge.net/problem/POJ-3484
题目大意:
给出一系列等差数列,给出第一项和最后一项和公差
这些等差数列中每个数出现的次数只有一个是奇数,找出这个数,并求出其出现的次数
解题思路:
二分枚举这个数,但是只是二分这个数字的话,找不到二分的条件。
所以枚举判断的时候,求出小于等于这个数字的数有多少个,如果是奇数个,说明该数 >= 解
如果是偶数,该数 < 解
输入很坑,数据与数据之间可能有多个空行
#include<cstdio>
#include<cstring>
#include<iostream> using namespace std;
typedef long long ll;
const int maxn = 1e7 + ;
const double eps = 1e-;
struct node
{
ll l, r, d;
}a[maxn];
int n;
bool read()
{
bool ok = ;
n = ;
char s[];
while(gets(s))
{
if(strlen(s) == )
{
if(ok)break;
continue;
}
ok = ;
sscanf(s, "%lld%lld%lld", &a[n].l, &a[n].r, &a[n].d);
n++;
}
return ok;
}
ll judge(ll mid)
{
ll tot = ;
for(int i = ; i < n; i++)
{
if(mid < a[i].l)continue;
if(mid > a[i].r)
tot += (a[i].r - a[i].l) / a[i].d + ;//注意加一,两种情况都需要加一
else
{
tot += (mid - a[i].l) / a[i].d + ;
}
}
return tot;
}
int main()
{
while(read())
{
ll l = , r = 1LL << , ans = ;
while(l <= r)
{
ll mid = (l + r) / ;
//cout<<mid<<" "<<judge(mid)<<endl;
if(judge(mid) & )
{
ans = mid;
r = mid - ;
}
else l = mid + ;
}
if(ans == )
{
printf("no corruption\n");
continue;
}
ll tot = ;
for(int i = ; i < n; i++)
{
if(ans >= a[i].l && ans <= a[i].r && ((ans - a[i].l) % a[i].d == ))tot++;
}
printf("%lld %lld\n", ans, tot);
}
return ;
}
POJ-3484 Showstopper---二分+前缀和的更多相关文章
- Poj 3061 Subsequence(二分+前缀和)
Subsequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12333 Accepted: 5178 Descript ...
- POJ 3484 Showstopper(二分答案)
[题目链接] http://poj.org/problem?id=3484 [题目大意] 给出n个等差数列的首项末项和公差.求在数列中出现奇数次的数.题目保证至多只有一个数符合要求. [题解] 因为只 ...
- poj 3484 Showstopper
Showstopper Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2236 Accepted: 662 Descri ...
- poj 3061 Subsequence 二分 前缀和 双指针
地址 http://poj.org/problem?id=3061 解法1 使用双指针 由于序列是连续正数 使用l r 表示选择的子序列的起始 每当和小于要求的时候 我们向右侧扩展 增大序列和 每当和 ...
- POJ 3061 (二分+前缀和or尺取法)
题目链接: http://poj.org/problem?id=3061 题目大意:找到最短的序列长度,使得序列元素和大于S. 解题思路: 两种思路. 一种是二分+前缀和.复杂度O(nlogn).有点 ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree 树上二分+前缀和思想
题目链接: http://codeforces.com/contest/740/problem/D D. Alyona and a tree time limit per test2 secondsm ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- Divide and conquer:Showstopper(POJ 3484)
Showstopper 题目大意:数据挖掘是一项很困难的事情,现在要你在一大堆数据中找出某个数重复奇数次的数(有且仅有一个),而且要你找出重复的次数. 其实我一开始是没读懂题意的...主要是我理解错o ...
- POJ 3484 二分
Showstopper Description Data-mining huge data sets can be a painful and long lasting process if we a ...
随机推荐
- Jquery 循环内间隔执行 异步执行
<script type="text/javascript"> var arr = new Array(); var arrk = 0; jQuery(function ...
- 常用维护SQL-数据清理
truncate某个库的表数据 show full processlist; select concat('truncate table ',table_schema,'.',table_name,' ...
- IOS下去掉input submit圆角和
在iOS系统下input submit会有圆角,如果添加有背景色,背景色出错,在安卓系统是没有这些问题,可以在input样式加上这段样式 input{ -webkit-appearance: none ...
- 《阿里如何实现秒级百万TPS?搜索离线大数据平台大数据平台架构解读》读后感
在使用淘宝时发现搜索框很神奇,它可以将将我们想要的商品全部查询出来,但是我们并感觉不到数据库查询的过程,速度很快.通过阅读这篇文章让我知道了搜索框背后包含着很多技术,对我以后的学习可能很有借鉴. 平时 ...
- IT职场?未来?
转自 IT职场?未来? 不能否认,有些技术大牛,生活也过的不错,工资不少挣.但是这种人,本来就不多啊,很少啊.这些人一般都是小时候就搞程序的,你觉得你半路出家,能变成这种超级牛人么?? 而且这些牛人, ...
- Python学习 day05
数据类型划分 数据类型可分为:可变数据类型,不可变数据类型 不可变数据类型:bool.int.str.元祖 -- 不可变数据类型又称为可哈希的 可变数据类型:list.dict.se ...
- 解决eclipse中org.w3c.dom.Node类老报The method getTextContent() is undefined 问题
http://www.cnblogs.com/itspy007/articles/4431581.html
- 前台通过ajax获取后台数据,PHP如何返回中文数据
现在经常使用Ajax调用后台php获取后台数据,但是PHP返回的数据如果含有中文的话,Ajax会无法识别,那咋整呢,我用的是比较笨的方法,但是实用: 方法一: echo urldecode(json_ ...
- iis6、iis7、apache设置mime类型
1.IIS6添加方法. 打开iis,展开网站,右键要设置的站点--属性.找到“http头”选项卡--mime类型 进行设置添加. 截图以.ipa mime类型举例. 2.IIS7(iis7.5.iis ...
- SpringSecurity 3.2入门(5)自定义登录页面
增加spring-security.xml文件配置如下 <!-- 配置SpringSecurity的http安全服务 --> <security:http auto-config=& ...