poj 1759 二分搜索
题意:N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数?
思路:
- 因为只有一个数出现的次数为奇数个
- 假设 第二个数字的个数为 奇数个,其余全部都是偶数个 ,累计出现的次数
a1偶数
a1+a2 奇数
a1+a2+a3 奇数
...................
会出现这种情况:偶偶偶...偶奇
第一个出现奇的就是我们想要的
解决问题的代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <cstring>
using namespace std;
#define maxn 50010
typedef long long ll;
ll x[maxn], y[maxn], z[maxn];
int cnt;
char s[maxn];
ll judge(ll mid)
{
ll sum = ;
for (int i = ; i < cnt; i++)
{
if (mid < x[i]) continue;
ll t = min(mid, y[i]);
sum += (t - x[i]) / z[i] + ;
}
return sum;
}
void solve()
{
cnt = ;
x[] = ;
sscanf(s, "%lld%lld%lld", &x[], &y[], &z[]);
if (!x[]) return; while (gets_s(s) && s[])
{
sscanf(s, "%lld%lld%lld", &x[cnt], &y[cnt], &z[cnt]);
cnt++;
}
ll l = , r = 1ll << ;
while (l < r)
{
ll mid = (l + r) / ;
if (judge(mid) % ) r = mid;
else l = mid + ;
}
if (l == 1ll << ) printf("no corruption\n");
else printf("%lld %lld\n", l, judge(l) - judge(l - ));
}
int main()
{
while (gets_s(s))
solve();
return ;
}
poj 1759 二分搜索的更多相关文章
- POJ 1759 Garland(二分+数学递归+坑精度)
POJ 1759 Garland 这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...
- poj 1759 Garland (二分搜索之其他)
Description The New Year garland consists of N lamps attached to a common wire that hangs down on th ...
- POJ 1759 Garland(二分答案)
[题目链接] http://poj.org/problem?id=1759 [题目大意] 有n个数字H,H[i]=(H[i-1]+H[i+1])/2-1,已知H[1],求最大H[n], 使得所有的H均 ...
- poj 1759 Garland
Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2365 Accepted: 1007 Descripti ...
- poj 2976(二分搜索+最大化平均值)
传送门:Problem 2976 参考资料: [1]:http://www.hankcs.com/program/cpp/poj-2976-dropping-tests-problem-solutio ...
- poj 1759(二分)
传送门:Problem 1759 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N个彩灯关在同一条绳上,给出第一个彩灯的高度A,并给 ...
- Pie POJ 3122 二分搜索
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17324 Accepted: 5835 Special Judge ...
- Divide and conquer:Garland(POJ 1759)
挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...
- POJ 1759
Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1236 Accepted: 547 Descriptio ...
随机推荐
- Java学习笔记——集合
类集简介 从JDK1.2开始Java引入了类集开发框架,所谓的类集指的就是一套动态对象数组的实现方案,在实际开发之中没有有何一项开发可以离开数组,但是传统的数组实现起来非常的繁琐.而且长度是其致命伤, ...
- 诸葛io | 精细化运营分析解决方案
类型: 定制服务 软件包: business intelligence internet media solution collateral 联系服务商 产品详情 解决方案 概要 数据监测 ? 异常发 ...
- 青石B2C商城
平台: Windows 类型: 虚拟机镜像 软件包: azure commercial ecbluestone ecommerce ecommerce solution 服务优惠价: 按服务商许可协议 ...
- Google面试准备
本人小弱,面试过了Google的HC,虽然team match还没完成,到最后还有变数.但对自己这段时间的努力,也算一个交代了. 最初是一年半前Google的HR联系到我,然后第一次在电面就挂了.经过 ...
- centos系统下安装Nginx
参考链接 CentOS 7 用 yum 安装 Nginx Nginx负载均衡配置 下载并安装 #使用以下命令 sudo yum install -y nginx #sudo表示使用管理员权限运行命令 ...
- 在windows bat脚本(batch)中延时
编写bat脚本时,有事我们希望在指令和指令之间,加入延时.例如当一条指令执行后,windows需要一定时间来响应的情况. 以下是一种实现方法,通过ping 指令来实现,5表示ping5次,就是延时5秒 ...
- java IO流——字节流
字节流主要操作byte类型数据,以byte数组为准,主要操作类有InputStream(字节输入流).OutputSteam(字节输出流)由于IputStream和OutputStream都是抽象类, ...
- IOS 解析XML数据
● 什么是XML ● 全称是Extensible Markup Language,译作“可扩展标记语言” ● 跟JSON一样,也是常用的一种用于交互的数据格式 ● 一般也叫XML文档(XML ...
- 进程—内存描述符(mm_struct)
http://blog.csdn.net/qq_26768741/article/details/54375524 前言 上一篇我们谈论了task_struct这个结构体,它被叫做进程描述符,内部成员 ...
- Map的嵌套,HDU(1263)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1263 新学的map的嵌套 #include <stdio.h> #include < ...