题目链接

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之间。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <cstdlib>
  7. #include <algorithm>
  8. #define LL __int64
  9. const int maxn = +;
  10. using namespace std;
  11. LL y[maxn];
  12. int check(LL x)
  13. {
  14. int sum = ;
  15. while(x)
  16. {
  17. sum += x%;
  18. x /= ;
  19. }
  20. return sum;
  21. }
  22. LL pow_m(int a, int b)
  23. {
  24. LL ret = ;
  25. for(int i = ; i <= b; i++)
  26. ret *= a;
  27. return ret;
  28. }
  29. int main()
  30. {
  31. LL a, b, c, i;
  32. int cnt;
  33. LL tmp;
  34. while(~scanf("%I64d%I64d%I64d", &a, &b, &c))
  35. {
  36. cnt = ;
  37. memset(y, , sizeof(y));
  38. for(i = ; i <= ; i++)
  39. {
  40. //tmp = (LL)pow(i, a); //用这个我的程序跑的数据对,但是测试数据不对
  41. tmp = pow_m(i, a);
  42. tmp = (LL)tmp*b + (LL)c;
  43. if(check(tmp)==i)
  44. {
  45. if(tmp > && tmp < )
  46. y[cnt++] = tmp;
  47. }
  48. }
  49. sort(y, y+cnt);
  50. printf("%d\n", cnt);
  51. for(i = ; i < cnt; i++)
  52. {
  53. if(i==cnt-)
  54. printf("%I64d\n", y[i]);
  55. else
  56. printf("%I64d ", y[i]);
  57. }
  58. }
  59. return ;
  60. }

Present

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

分析:

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

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

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <cstdlib>
  7. #include <algorithm>
  8. #define LL __int64
  9. const int maxn = +;
  10. using namespace std;
  11. int a[maxn], f[maxn];
  12.  
  13. int main()
  14. {
  15. int i, n, m, w, y;
  16. int low, mid, hig, tmp, ans, t2;
  17. while(~scanf("%d%d%d", &n, &m, &w))
  18. {
  19. for(i = ; i < n; i++)
  20. {
  21. scanf("%d", &a[i]);
  22. if(i==) low = a[i];
  23. else if(a[i]<low)
  24. low = a[i];
  25. }
  26. hig = m+low;
  27. while(hig>=low)
  28. {
  29. y = m;
  30. tmp = ;
  31. memset(f, , sizeof(f));
  32. mid = (low+hig)/;
  33. for(i = ; i < n; i++)
  34. {
  35. t2 = a[i];
  36. tmp -= f[i]; //先减去已经在增加范围之外的。
  37. t2 += tmp;
  38. if(t2 < mid)
  39. {
  40. y -= mid-t2;
  41. if(i+w<n)
  42. f[i+w] += mid-t2; //f数组记录到w个以后的不会加上mid-t2。
  43. tmp += mid-t2; //记录前面增加的值
  44. }
  45. if(y < ) break;
  46. }
  47. if(y>=)
  48. {
  49. low = mid+;
  50. ans = mid; //记录下合法的答案,一直到最高点
  51. }
  52. else
  53. hig = mid-; //减去1
  54. }
  55. printf("%d\n", ans);
  56. }
  57. return ;
  58. }

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. 包装设计模式的实现以改进BufferedReader中的readLine方法为例

    实现与目标对象相同的接口     BufferedReader 定义一个变量记住目标对象 定义一个构造器接收被增强对象 覆盖需要增强的方法 对于不想增强的方法,直接调用目标对象的方法. package ...

  2. 为什么V8引擎这么快?(转载)

    转载请注明出处:http://blog.csdn.net/horkychen Google研发的V8 JavaScript引擎性能优异.我们请熟悉内部程序实现的作者依源代码来看看V8是如何加速的. 作 ...

  3. 编译dubbo2.5.4时遇到的问题及解决

    dubbo的官方git地址为:https://github.com/alibaba/dubbo 按照其流程进行下载及编译,遇到的问题为: 1. 执行 mvn clean install -Dmaven ...

  4. PHP的会话处理函数session

    (๑•ᴗ•๑) PHP Session 变量 当运行一个应用程序时,你会打开它,做些更改,然后关闭它.这很像一次会话.计算机清楚你是谁.它知道你何时启动应用程序,并在何时终止.但是在因特网上,存在一个 ...

  5. dbutils报错:com.microsoft.sqlserver.jdbc.SQLServerException: 无法识别元数据的表

    今天用dbutils操作数据库,莫名地报错:com.microsoft.sqlserver.jdbc.SQLServerException: 无法识别元数据的表 检查了sql语句没有问题.经过仔细排查 ...

  6. log4j 总结 精华

    去年这个时候,为做软件工程的大作业就详细学过Log4J的用法了,时隔一年想要在新的项目中好好使用一下的时候,发现几乎全忘了,悲催啊…… 再上网查资料,总是不能找到一篇符合我的口味,拿来就能轻松上手,方 ...

  7. POJ 3111

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 5177   Accepted: 1411 Case Time ...

  8. POJ 1182 食物链(种类并查集)

    记得第一次做这道题的时候,推关系感觉有点复杂,而且写完代码后一直WA,始终找不出错误. 在A了十几道并查集后,再做这道题,发现太小儿科了.发现原来之所以WA,就在于查找根节点时,没有同步更新子节点相对 ...

  9. C#和Javascript中 正则表达式使用的总结

    说明:本文并非原创,而是从网站上搜集了一些资料整理的!如有雷同,纯属巧合 1.js中正则表达式的使用 在js中定义正则表达式很简单,有两种方式,一种是通过构造函数,一种是通过//,也就是两个斜杠.例如 ...

  10. lintcode :Reverse Words in a String 翻转字符串

    题目: 翻转字符串 给定一个字符串,逐个翻转字符串中的每个单词. 样例 给出s = "the sky is blue",返回"blue is sky the" ...