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 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...
随机推荐
- Wijmo Angular 2 小应用
Wijmo & Angular 2 小应用 中秋之际,Angular 团队发布 Angular 2 正式版,一款不错的图表控件Wijmo当天宣布支持 . Angular 2移除和替代了 Ang ...
- Interview-Largest independent set in binary tree.
BT(binary tree), want to find the LIS(largest independent set) of the BT. LIS: if the current node i ...
- Linux内核分析作业二—操作系统是如何工作的
一.实验:简单的时间片轮转多道程序内核代码运行与分析 my_start_kernel之前都是硬件初始化,它是操作系统的执行入口,每循环100000次就进行一次打印. 执行更加简单,每次时钟中断时都会调 ...
- bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...
- How to avoid C# console applications from closing automatically.
One way is to interop it with msvcrt.dll You can pinvoke this C function into your C# application. T ...
- [转载]ASP.NET对路径"xxxxx"的访问被拒绝的解决方法小结
异常详细信息: System.UnauthorizedAccessException: 对路径“D:/temp1/MyTest.txt”的访问被拒绝 在windows 2003下,在运行web ...
- TensorFlow 基本使用
使用 TensorFlow, 你必须明白 TensorFlow: 使用图 (graph) 来表示计算任务. 在被称之为 会话 (Session) 的上下文 (context) 中执行图. 使用 ten ...
- 已收录的帝国cms文章被误删除了怎么办?
我们一直提倡网站要经常备份,但是有时也会遗忘,一不小心被谁删除了那就欲哭无泪了.就像ytkah刚弄了一个站,开了个权限比较高的后台帐号给别人用,居然把两三个栏目都删除了,想发狂啊.刚好又有段时间没备份 ...
- G家二面
题目都很基本,都属于听说过但是不会做的…都是操作系统,compiler的概念题… 概念题郁闷就郁闷在不会就是不会,就算能扯两句也会被问倒… 算法就一个,pow(x, y),5分钟不到…… 不是听说G家 ...
- 【leetcode】Majority Element (easy)(*^__^*)
Given an array of size n, find the majority element. The majority element is the element that appear ...