题目链接

Little Dima and Equation

题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x.

分析:直接枚举x肯定超时,会发现s(x)范围只有只有1-81,所以枚举一下就行。

在做题的时候,用了pow()错了3次,反正以后不用pow了,还是手写吧。会有误差。pow返回的是double型的。

昨天在b题耽误了好多时间,先是提交错第一组,然后又被人cha了。注意在x在1-10^9之间。

 #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL __int64
const int maxn = +;
using namespace std;
LL y[maxn];
int check(LL x)
{
int sum = ;
while(x)
{
sum += x%;
x /= ;
}
return sum;
}
LL pow_m(int a, int b)
{
LL ret = ;
for(int i = ; i <= b; i++)
ret *= a;
return ret;
}
int main()
{
LL a, b, c, i;
int cnt;
LL tmp;
while(~scanf("%I64d%I64d%I64d", &a, &b, &c))
{
cnt = ;
memset(y, , sizeof(y));
for(i = ; i <= ; i++)
{
//tmp = (LL)pow(i, a); //用这个我的程序跑的数据对,但是测试数据不对
tmp = pow_m(i, a);
tmp = (LL)tmp*b + (LL)c;
if(check(tmp)==i)
{
if(tmp > && tmp < )
y[cnt++] = tmp;
}
}
sort(y, y+cnt);
printf("%d\n", cnt);
for(i = ; i < cnt; i++)
{
if(i==cnt-)
printf("%I64d\n", y[i]);
else
printf("%I64d ", y[i]);
}
}
return ;
}

Present

题意:给一串n个数字,可以对连续的w个数字增加1,共增加m次,问增加完以后最小的数字是多少,让求所有方法里最小数字的最大值。

分析:

对结果二分就行了,即二分最小的值,然后都符合的话,往上加一个。

这个题和poj计划上的那两个二分题差不多,比赛的时候因为前面的b题实在是脑残了,做这个题没时间了,当时思路也不是很好,没写出来。

 #include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL __int64
const int maxn = +;
using namespace std;
int a[maxn], f[maxn]; int main()
{
int i, n, m, w, y;
int low, mid, hig, tmp, ans, t2;
while(~scanf("%d%d%d", &n, &m, &w))
{
for(i = ; i < n; i++)
{
scanf("%d", &a[i]);
if(i==) low = a[i];
else if(a[i]<low)
low = a[i];
}
hig = m+low;
while(hig>=low)
{
y = m;
tmp = ;
memset(f, , sizeof(f));
mid = (low+hig)/;
for(i = ; i < n; i++)
{
t2 = a[i];
tmp -= f[i]; //先减去已经在增加范围之外的。
t2 += tmp;
if(t2 < mid)
{
y -= mid-t2;
if(i+w<n)
f[i+w] += mid-t2; //f数组记录到w个以后的不会加上mid-t2。
tmp += mid-t2; //记录前面增加的值
}
if(y < ) break;
}
if(y>=)
{
low = mid+;
ans = mid; //记录下合法的答案,一直到最高点
}
else
hig = mid-; //减去1
}
printf("%d\n", ans);
}
return ;
}

Codeforces Round #262 (Div. 2) 二分+贪心的更多相关文章

  1. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  2. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  3. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

  4. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  5. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  6. Codeforces Round #262 (Div. 2)C(二分答案,延迟标记)

    这是最大化最小值的一类问题,这类问题通常用二分法枚举答案就行了. 二分答案时,先确定答案肯定在哪个区间内.然后二分判断,关键在于怎么判断每次枚举的这个答案行不行. 我是用a[i]数组表示初始时花的高度 ...

  7. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  8. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

  9. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

随机推荐

  1. java使用.net的webservice

    1.下载最新的axis2 http://mirrors.hust.edu.cn/apache//axis/axis2/java/core/1.6.3/axis2-1.6.3-bin.zip 2.解压使 ...

  2. 设置NODE_ENV=production

    NodeJS - Express 4.0下设置环境变量NODE_ENV=production,并不是修改文件的配置信息,而是通过命令行来实现. 首先在命令行下进入项目的目录,然后先后执行如下命令: s ...

  3. 11.1Daily Scrum

    人员 任务分配完成情况 明天任务分配 王皓南 主网页的框架搭建,任务编号760 研究代码,学习相应语言,讨论设计思路 申开亮 学习数据库的操作,任务编号761 研究代码,学习相应语言,讨论设计思路 王 ...

  4. Python Socket File Transfer

    I have a RPi which I intented to use it to crawl data. The development environment in RPi is very ba ...

  5. action间传多个参数时注意问题

    通常我们action之间传参可以有多种形式,举例说明:示例1: <result name="test" type="redirect-action"> ...

  6. map中的erase成员函数用法

    转载于 http://www.cnblogs.com/graphics/archive/2010/07/05/1771110.html  http://hi.baidu.com/sdkinger/it ...

  7. PHP对XML文件操作之属性与方法讲解

    DOMDocument相关的内容. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点的子节点列表(只读) dataType 返回此节点的数据类型 Definit ...

  8. C# 连接Oracle数据库

    最近项目要用Oracle数据库,之前没搞过,近2天遇到好多问题,现在总结一下,做个备份. 一.关于Oracle安装 1.服务器端 从Oracle官网下载文件,file1和file2,解压之后安装就行了 ...

  9. HDU 3461 Code Lock(并查集,合并区间,思路太难想了啊)

    完全没思路,题目也没看懂,直接参考大牛们的解法. http://www.myexception.cn/program/723825.html 题意是说有N个字母组成的密码锁,如[wersdfj],每一 ...

  10. utmp, wtmp, and lastlog 日志清除工具

    utmp, wtmp, and lastlog 日志清除工具 http://blog.itpub.net/83980/viewspace-801664/