题意: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. vue2 关于ref

    1,VUE2子组件索引 <div id="app"> <navbar></navbar> <pagefooter></page ...

  2. 让DIV的滚动条自动滚动到最底部

    一个在线聊天窗口,在做最后的修饰时,需要对获得的信息即时滚动以保证用户总能看到最新消息. 我得出的结论是:在选中div时,必须用原生js,jQuery不起作用 <!DOCTYPE> < ...

  3. RAL调用

    [RPC的定义].RPC的全称为 Remote Procedure Call(远程过程调用).远程过程调用是一个计算机通信协议.该协议允许运行于一台计算机的程序调用另一台计算机的子程序,而程序员无需额 ...

  4. SharePoint中低权限用户通过提升权限创建用户组

    /// <summary> /// 提升权限创建用户组 /// </summary> /// <param name="groupname">用 ...

  5. java中将数组、对象、Map、List转换成JSON数据

    如果要将数组.对象.Map.List转换成JSON数据,那我们需要一些jar包: json-lib-2.4-jdk15.jar ezmorph-1.0.6.jar commons-logging.ja ...

  6. Spark资源管理

    Spark资源管理 1.介绍 Spark资源管控分为spark集群自身可支配资源配置和job所用资源配置. 2.spark集群支配资源控制 在spark的conf/spark-env.sh文件中可以指 ...

  7. Spring MVC框架下提交Date数据无法在controller直接接收

    主要有两步,controller中添加initBinder方法,再创建一个时间类型数据转换类就OK了. 1.在Controller中创建方法: // 相关包 import java.text.Date ...

  8. 504. Inverted Index (Map Reduce) lintcode

    https://www.lintcode.com/problem/inverted-index-map-reduce/description -- decription of the map redu ...

  9. windows 右健添加cmd快捷通道

    windows 右健添加cmd快捷 - Windows - geektown极客堂 - Powered by Discuz!. 把横线下面的文本copy保存到一个注册表文件中,比如cmd.reg,然后 ...

  10. QT创建与调用Dll方法(包括类成员)--显式调用

    看网上的好多关于QT调用Dll的方法,大部分都是调用函数的,并没有调用C++类成员的情况,即使是有,比如说: 使用Qt编写模块化插件式应用程序 Qt 一步一步实现dll调用(附源码)---(这一篇里没 ...