题意: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. js获取文件上传进度

    js获取文件上传进度: <input name="file" id="FileUpload" type="file" /> &l ...

  2. angular的多个模块执行 angular里 字符串与对象的互转

    1.disable : true ,禁用 2.$timeout 计时器 $interval.cancel(timer); 3.app.run();  可以不使用控制器就开启数据,但适合$rootsco ...

  3. Eclipse导入web项目后,run列表中没有run on server?

    Eclipse导入web项目,没有run列表中run on server? 首先确保正确安装Tomcat和JDK .找到对于web项目的文件夹,打开文件夹下.project文件 <?xml ve ...

  4. 【Troubleshooting 】Outlook 客户端无法显示电子邮件图像

    出于安全原因,Outlook 2013/2016不会在电子邮件中显示图像,但您可以右键单击图像并选择" 下载图片 "选项.我最近注意Outlook停止显示图像,并且没有下载图像的选 ...

  5. VS2015卸载方法

    VS2015卸载 直接再控制面板的卸载程序中找到 VS2015 的程序,邮件更改,安装程序会被打开,里面有三个选项包含卸载,点击卸载[记得在卸载前如果有打开过 VS 最好重启一下,重启后不要打开 VS ...

  6. 关于 no device found for connection ‘ System eth0′问题

    在Vmware上面安装CentOS,开机后,使用:service network restart时,会提示一下错误: Shutting down loopback interface:         ...

  7. 制作URL以GET方式提交的简单加密程序

    首先我们用到的是 DESCryptoServiceProvider 类 对此微软给出的解释是 定义访问数据加密标准 (DES) 算法的加密服务提供程序 (CSP) 版本的包装对象.无法继承此类. 接下 ...

  8. 快餐店之间插入仓库,路最短,DP,POJ(1485)

    题目链接:http://poj.org/problem?id=1485 暂时我还没想出思路求路径.哈哈哈,先写一下中间步骤吧. #include <stdio.h> #include &l ...

  9. javaweb基础(37)_mysql数据库自动生成主键

    测试脚本如下: 1 create table test1 2 ( 3 id int primary key auto_increment, 4 name varchar(20) 5 ); 测试代码: ...

  10. Shell编程学习之重定向

    这一篇讲一下重定向 有些时候你想要保存某些命令产生的输出而不是在显示器上显示它. 为了应对这样的问题 bash shell 也就提供了一些重定向的操作符. 我们先了解一些基本的应用. 输出重定向 输出 ...