版权声明:本文为博主原创文章,未经博主同意不得转载。

https://blog.csdn.net/u011639256/article/details/28100041

题读错了啊。。。

一直跪,但刚開始我的思路是正确的

假设做出来了rating一定会暴涨的

我的方法是找出1到100000全部数相应的lowbit()值

再暴力,可惜题读错了,lowbit的意思是找出该数二进制数从右向左1出现的最早位置相应的数值

代码例如以下:

  1. #include <cmath>
  2. #include <stack>
  3. #include <cstdio>
  4. #include <iostream>
  5. #include <algorithm>
  6. #define MAXN 100010
  7. #define ll long long
  8. using namespace std;
  9. int a[] = {1, 2, 4, 8, 16, 32, 64, 128,
  10. 256, 512, 1024, 2048, 4096, 8192,
  11. 16384, 32768, 65536, 131072};
  12. int b[MAXN];
  13. int c[MAXN];
  14. ll sum[MAXN];
  15. void f(void) {
  16. sum[0] = 0;
  17. for(int i=1; i<MAXN; ++i) {
  18. for(int j=0; j<18; ++j) {
  19. if(i & a[j]) {
  20. b[i] = a[j];
  21. break;
  22. }
  23. }
  24. sum[i] = sum[i-1]+b[i];
  25. }
  26. return ;
  27. }
  28. int main(void) {
  29. ll s, k;
  30. int tmp;
  31. f();
  32. while(cin >> s >> k) {
  33. int cnt = 0;
  34. if(s > sum[k]) {
  35. printf("-1\n");
  36. continue;
  37. }
  38. for(int i=k; i>0; --i) {
  39. if(s-b[i] > 0) {
  40. s -= b[i];
  41. c[cnt++] = i;
  42. }
  43. else if(s-b[i] == 0) {
  44. c[cnt++] = i;
  45. break;
  46. }
  47. }
  48. printf("%d\n", cnt);
  49. printf("%d", c[0]);
  50. for(int i=1; i<cnt; ++i)
  51. printf(" %d", c[i]);
  52. cout << endl;
  53. }
  54. return 0;
  55. }

Codeforces #250 (Div. 2) B. The Child and Set的更多相关文章

  1. Codeforces #250 (Div. 2) C.The Child and Toy

    之前一直想着建图...遍历 可是推例子都不正确 后来看数据好像看出了点规律 就抱着试一试的心态水了一下 就....过了..... 后来想想我的思路还是对的 先抽象当前仅仅有两个点相连 想要拆分耗费最小 ...

  2. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  3. Codeforces Round #250 (Div. 1) B. The Child and Zoo 并查集

    B. The Child and Zoo Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...

  4. Codeforces Round #250 (Div. 1) A. The Child and Toy 水题

    A. The Child and Toy Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/ ...

  5. Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)

    题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...

  6. Codeforces Round #250 (Div. 2)—A. The Child and Homework

         好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人  被HACK  1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...

  7. Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树)

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  8. Codeforces Round #250 (Div. 1) D. The Child and Sequence

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  9. Codeforces Round #250 (Div. 2) D. The Child and Zoo 并查集

    D. The Child and Zoo time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

随机推荐

  1. 使用vue配合组件--转载

    1.由饿了么 UED (知乎专栏)设计的桌面端组件库已经开源,文档:Element,仓库: GitHub - ElemeFE/element: Desktop UI elements for Vue. ...

  2. python学习第四天-函数

    函数  def开头 函数参数 其中name.age.sex为形参,'王锦时',21,'男'为实参 函数返回值 默认参数 关键字参数 收集参数 相当于把所有实参存在一个元组当中 收集参数和关键字参数的混 ...

  3. HDU 4366 Successor( DFS序+ 线段树 )

    Successor Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  4. java虚拟机规范(se8)——java虚拟机的编译(三)

    3.6 接受参数 如果n个参数传给一个实例的方法,按照约定,它们被接受并放在这个新方法创建的栈帧中的局部变量表里,在局部变量表中的序号从1到n.这些参数按照它们传递过来的顺序存放.例如: int ad ...

  5. 解决MVC中textarea出现多余空格的问题

    public static MvcHtmlString FixedTextAreaFor<TModel, TProperty>(this HtmlHelper<TModel> ...

  6. Java模拟HttpClient进行Get和Post提交

    使用Java模拟客户端进行提交,需要用到apache http client jar,这里用的是4.4版本 GET: public void GetURL(){  String strResp=&qu ...

  7. 2018-2-13-关于Host(主机)

    title author date CreateTime categories 关于Host(主机) lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23:3 ...

  8. linux-tomcat-install

    1.解压: tar zxvf xxx.tar.gz 配置JDK的环境变量,在etc/profile文件中添加 2.修改Tomcat启动端口 cd tomcat/conf/server.xml中的con ...

  9. 【虚拟机】:"该虚拟机似乎正在使用中。 如果该虚拟机未在使用,请按“获取所有权(T)”按钮获取它的所有权。否则,请按“取消(C)”按钮以防损坏。"

    1.可能是由于上次使用虚拟机,没有正常关闭出现了这种情况,于是把问题复制粘贴搜了一下. 2.出现了如下可行的解决方法:把后缀名为.vmdk.lck的都删除掉. 3.然后再打开虚拟机就可以了.

  10. jenkins发送邮箱配置,出现Error sending to the following VALID addresses,解决方案

    Jenkins发送邮箱配置,需要的插件:Extended E-mail Notification,邮件通知 1.Manage Jenkins -> Configure System 2.下图是“ ...