题目链接

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. js 正则 数值验证

    function checkTextDataForNORMAL(strValue) { // 特殊字符验证格式 var regTextChar = /([\*"\'<>\/])+ ...

  2. 用MSBuild和Jenkins搭建持续集成环境 - 转

    http://www.infoq.com/cn/articles/MSBuild-1 http://www.infoq.com/cn/articles/MSBuild-2 MSBuild是在.NET ...

  3. Codeforces Round #352 (Div. 2) D. Robin Hood

    题目链接: http://codeforces.com/contest/672/problem/D 题意: 给你一个数组,每次操作,最大数减一,最小数加一,如果最大数减一之后比最小数加一之后要小,则取 ...

  4. IntelliJ IDEA 15 部署Tomcat及创建一个简单的Web工程

    一.部署Tomcat 二.创建一个简单的Web工程 2.1创建一个新工程 创建一个新工程 设置JDK及选择Web Application (创建的是Web工程) 点击Next,选择工作空间,起个工程名 ...

  5. IntelliJ IDEA创建项目技巧(转)

    转自:http://www.myext.cn/webkf/a_2539.html IntelliJ IDEA创建项目技巧 来源:网络    编辑:admin intellij idea教程 首先我要说 ...

  6. 剑指offer--面试题10

    题目:求整数二进制表示中1的个数. 分析:此题直接考查二进制表示与位运算!!! 正数和负数的二进制表示不同!在计算机中,正数的二进制表示即为通常所写的二进制:而负数的二进制表示则用补码表示,即原码的反 ...

  7. NYOJ-456 邮票分你一半 AC 分类: NYOJ 2014-01-02 14:33 152人阅读 评论(0) 收藏

    #include<stdio.h> #define max(x,y) x>y?x:y int main(){ int n,x,y; scanf("%d",& ...

  8. UI框架说明

    JQueryEasyUI jQuery EasyUI是一组基于jQuery的UI插件集合,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开发者不需要编 ...

  9. Remote Desktop manager 连接后无法自动登录

    现象: Remote Desktop manager 连接后无法自动登录 用Windows 自带的远程桌面 可以自动登录 解决方法: 在指定站点 右键 Edit Entry. 如下图处打勾就可以了.

  10. NGUI Tutorial 3

    一. Create a Button 一.(Menu)NGUI -> Create -> Sprite 二.attach box colider to the Sprite , then ...