题意:N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数?

思路:

  1. 因为只有一个数出现的次数为奇数个
  2. 假设 第二个数字的个数为 奇数个,其余全部都是偶数个 ,累计出现的次数

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 二分搜索的更多相关文章

  1. POJ 1759 Garland(二分+数学递归+坑精度)

    POJ 1759 Garland  这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...

  2. poj 1759 Garland (二分搜索之其他)

    Description The New Year garland consists of N lamps attached to a common wire that hangs down on th ...

  3. 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均 ...

  4. poj 1759 Garland

    Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2365   Accepted: 1007 Descripti ...

  5. poj 2976(二分搜索+最大化平均值)

    传送门:Problem 2976 参考资料: [1]:http://www.hankcs.com/program/cpp/poj-2976-dropping-tests-problem-solutio ...

  6. poj 1759(二分)

    传送门:Problem 1759 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N个彩灯关在同一条绳上,给出第一个彩灯的高度A,并给 ...

  7. Pie POJ 3122 二分搜索

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17324   Accepted: 5835   Special Judge ...

  8. Divide and conquer:Garland(POJ 1759)

     挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...

  9. POJ 1759

    Garland Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1236   Accepted: 547 Descriptio ...

随机推荐

  1. 背景图片之background的用法

    常用的background背景属性有: background-color 设置颜色作为对象背景颜色background-image 设置图片作为背景图片background-repeat 设置背景平铺 ...

  2. foxmail6.5 不能收取电子邮件,反复提示输入密码?

    使用foxmail时候报错:-err system resource error,system close connect,code=<1014>,id=<1>重新输入密码吗? ...

  3. css3照片墙

    一张张照片散乱的撒在一起,鼠标悬浮时旋转放大并摆正,效果如下图(所有图片均来自网络),主要使用到的css3属性有:transition.transform(scale.rotateZ).box-sha ...

  4. 当你的域名是数字开头时如何命名java包路径

    例如:域名是1001y.net 理想的包路径是net.1001y,但由于java命名规范的问题,首字母不能为数字,这时我们只有两种选择: 1,net.$1001y 使用$符号作为首字母. 2,net. ...

  5. DP,得到最多苹果,(POJ2385)

    题目链接:http://poj.org/problem?id=2385 题意: 牛在两棵苹果树下收集苹果,牛只能在这两棵树之间走动w次,在t时刻,某棵树会掉下苹果. 解题报告: ///dp[t][w] ...

  6. 昂贵的聘礼,(最短路的应用),Poj(1063)

    题目链接:http://poj.org/problem?id=1062 很好的一道中文题. 思路: 把每种替换当做一条边,权重为交易优惠,就是求原点0到物品1的最短路. 这里有限制条件,每个节点还有等 ...

  7. 通过WEB网管登录

    6.1  通过WEB网管登录简介 S5100-SI/EI系列以太网交换机提供内置的WEB Server,用户可以通过WEB网管终端(PC)登录到交换机上,利用内置的WEB Server以WEB方式直观 ...

  8. 在控制台中 使用memcache

    控制台的代码 在memcache 中查询 hans,结果显示如下 :

  9. numpy中生成随机矩阵并打印出矩阵的shape

    from numpy import * c=zeros((4,5)) print c.shape print numpy.random.random((2,3))

  10. SQL随手记

    数据库改名 想要达到的效果,类似于将一个文件[复制粘贴重命名]. 0.首先得断开连接,复制一份备份.然后再连接上,进行下面的操作. 1.在树形上,选中要改名的数据库,右键重命名. 2.还是它,右键,属 ...