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 ...
随机推荐
- C++ Knowledge series 2
Programming language evolves always along with Compiler's evolvement The semantics of constructors O ...
- SharePoint中低权限用户通过提升权限创建用户组
/// <summary> /// 提升权限创建用户组 /// </summary> /// <param name="groupname">用 ...
- SPFieldLookupValue class
using System; using Microsoft.SharePoint; namespace ConsoleApp { class Program { static void Main(st ...
- SpringBoot支持Xml数据格式显示
第一步:pom文件添加依赖 <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> < ...
- 利用jQuery做登录界面的验证码
主要是为了有效防止机器恶意注册,对某一个特定已注册用户用特定程序暴力破解方式进行不断的登陆尝试.验证码是现在很多网站注册/登录时必填的, 虽然对用户可能有点麻烦,但是对网站/社区来说这个功能还是很有必 ...
- Linux 命令后台运行
写这个随笔主要是每次Deepin用shadowsocks的时候总需要命令行启动,然后一个终端就一直开着总是点错了就给关了. (不知道为什么我的Deepin的shadowsocks-qt5总是连接不上的 ...
- IOS 自定义Operation(下载功能)
一个下载操作就交给一个HMDownloadOperation对象 HMDownloadOperation.h / .m @class HMDownloadOperation; @protocol HM ...
- ios相关配置
Deployment Target,它控制着运行应用需要的最低操作系统版本.
- ADO.net中常用的对象有哪些?
ADO.net中常用的对象有哪些?分别描述一下. 答:Connection 数据库连接对像 Command 数据库命令 DataReader 数据读取器 DataSet 数据集 DataReader与 ...
- Onboard,迷人的引导页样式制作库
简介 Onboard主要用于引导页制作,源码写的相当规范,值得参考. 项目主页: https://github.com/mamaral/Onboard 实例下载: https://github.com ...