Codeforces Round #262 (Div. 2) 二分+贪心
题意:给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 ;
}
C 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) 二分+贪心的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #262 (Div. 2) A B C
题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...
- Codeforces Round #262 (Div. 2)C(二分答案,延迟标记)
这是最大化最小值的一类问题,这类问题通常用二分法枚举答案就行了. 二分答案时,先确定答案肯定在哪个区间内.然后二分判断,关键在于怎么判断每次枚举的这个答案行不行. 我是用a[i]数组表示初始时花的高度 ...
- Codeforces Round #547 (Div. 3) F 贪心 + 离散化
https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...
- Codeforces Round #262 (Div. 2)解题报告
详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks http ...
- Codeforces Round #595 (Div. 3)D1D2 贪心 STL
一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
随机推荐
- SSMS 2008R2没有智能感知方法解决
有时SSMS会莫明奇妙的没有了智能感知(前一天还是有的, 第2天就没有了) 在网上查到有如下原因: 1. 服务器上有Offline的DB 解决方案: 将Offline的DB删掉或者设成online即可 ...
- Notes of the scrum meeting(10/30)
meeting time:9:30~11:30p.m.,October 29th,2013 meeting place:20公寓楼前 attendees: 顾育豪 ...
- Sponsored Feature: Common Performance Issues in Game Programming
转自http://www.gamasutra.com/view/feature/132084/sponsored_feature_common_.php?print=1 By Becky Heinem ...
- android编程常见问题-程序真机中不显示
新手编程常见问题: 问题表现:连接上手机后,程序不显示 解决版本:检查AndroidManifest.xml 文件中SDK版本的设置(要求要兼容当前手机版本系统),如下:
- SSL 握手过程
SSL协议的握手过程 SSL 协议既用到了公钥加密技术又用到了对称加密技术,对称加密技术虽然比公钥加密技术的速度快,可是公钥加密技术提供了更好的身份认证技术.SSL 的握手协议非常有效的让客户和服务器 ...
- Unity3D脚本中文系列教程(八)
◆ static var matrix : Matrix4x4 描述:设置用于渲染所有gizmos的矩阵. 类方法 ◆ Static function DrawCube(center:Vector3, ...
- POJ1222 高斯消元法解抑或方程
第一次学怎么用高斯消元法解抑或方程组,思想其实很简单,方法可以看下面的链接:http://blog.csdn.net/zhuichao001/article/details/5440843 有了这种思 ...
- POJ 2407 Relatives(欧拉函数)
题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...
- eclipse 或MyEclipse将工程进行移动的时候会对@Override报错的处理方法
有时候导入javaSE,javaEE,android 工程的时候,明明是刚刚用过的没有问题的工程,但重新导入的时候就报错. 提示The method ... must override a sperc ...
- Android 用Activity的onTouchEvent来监听滑动手势
package com.example.activityOnTouchEvent; import android.app.Activity; import android.os.Bundle; imp ...