题意:

有n个数字,

要求在这n个数中选出至少两个数字,

使得它们的和在L,R之间,并且最大的与最小的差值要不小于x

思路:

撒比了啊。。。

根据状态的话一共也就是2^15…直接暴力,二进制的小魅力还是没能领会;

code……

  1. #include <bits/stdc++.h>
  2. #include<algorithm>
  3. using namespace std;
  4. typedef long long LL;
  5. const int N=1e6+10;
  6. int a[20];
  7. int main()
  8. {
  9. int n;
  10. int L,R;
  11. int x;
  12. int ans;
  13. scanf("%d%d%d%d",&n,&L,&R,&x);
  14. for(int i=0;i<n;i++)
  15. scanf("%d",&a[i]);
  16. ans=0;
  17. int st=1<<n;
  18. for(int i=1;i<=st;i++)
  19. {
  20. int cnt=0;
  21. int sum=0;
  22. int tmin=N;
  23. int tmax=-N;
  24. for(int j=0;j<n;j++)
  25. {
  26. if((1<<j)&i)
  27. {
  28. cnt++;
  29. tmax=max(tmax,a[j]);
  30. tmin=min(tmin,a[j]);
  31. sum+=a[j];
  32. }
  33. }
  34. if(cnt>=2&&sum>=L&&sum<=R&&(tmax-tmin)>=x)
  35. ans++;
  36. }
  37. printf("%d\n",ans);
  38. return 0;
  39. }

Codeforces 550B 【暴力】的更多相关文章

  1. CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)

    [题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...

  2. CodeForces 670D1 暴力或二分

    今天,开博客,,,激动,第一次啊 嗯,,先来发水题纪念一下 D1. Magic Powder - 1   This problem is given in two versions that diff ...

  3. Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分

    Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...

  4. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  5. Codeforces Round #425 (Div. 2) Problem B Petya and Exam (Codeforces 832B) - 暴力

    It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

  7. codeforces 691F 暴力

    传送门:https://codeforces.com/contest/691/problem/F 题意:给你n个数和q次询问,每次询问问你有多少对ai,aj满足ai*aj>=q[i],注意 a* ...

  8. Vicious Keyboard CodeForces - 801A (暴力+模拟)

    题目链接 题意: 给定一个字符串,最多更改一个字符,问最多可以有多少个“VK”子串? 思路: 由于数据量很小,不妨尝试暴力写.首先算出不更改任何字符的情况下有多个VK字串,然后尝试每一次更改一个位置的 ...

  9. (CodeForces 548B 暴力) Mike and Fun

    http://codeforces.com/problemset/problem/548/B Mike and some bears are playing a game just for fun. ...

随机推荐

  1. Android4.42-Setting源代码分析之蓝牙模块Bluetooth(下)

    接着上一篇Android4.42-Settings源代码分析之蓝牙模块Bluetooth(上) 继续蓝牙模块源代码的研究 THREE.蓝牙模块功能实现 switch的分析以及本机蓝牙重命名和可见性的分 ...

  2. 多线程网页爬虫 python 实现(二)

    #!/usr/bin/env python #coding=utf-8 import threading import urllib import re import time cur=0 last= ...

  3. js中对arry数组的各种操作小结 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据 web前端url传递值 js加密解密 HTML中让表单input等文本框为只读不可编辑的方法 js监听用户的键盘敲击事件,兼容各大主流浏览器 HTML特殊字符

    js中对arry数组的各种操作小结   最近工作比较轻松,于是就花时间从头到尾的对js进行了详细的学习和复习,在看书的过程中,发现自己平时在做项目的过程中有很多地方想得不过全面,写的不够合理,所以说啊 ...

  4. sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)

    sql server 关于表中只增标识问题   由于我们系统时间用的过长,数据量大,设计是采用自增ID 我们插入数据的时候把ID也写进去,我们可以采用 关闭和开启自增标识 没有关闭的时候 ,提示一下错 ...

  5. JS 计算2个日期相差的天数

    <span style="font-size:18px;">function getDays(strDateStart,strDateEnd){ var strSepa ...

  6. Beijing Bus

    Search: http://bjgj.aibang.com:8899 https://github.com/sp-chenyang/bus https://github.com/leavind/Co ...

  7. 淘宝数据库OceanBase SQL编译器部分 源码阅读--生成逻辑计划

    body, td { font-family: tahoma; font-size: 10pt; } 淘宝数据库OceanBase SQL编译器部分 源码阅读--生成逻辑计划 SQL编译解析三部曲分为 ...

  8. (转载)display:inline、block、inline-block的区别

    display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可控制: 宽度缺省是它的容器的100%,除非设定一个宽度 <div& ...

  9. Android - 监听Activity点击无效

    监听Activity点击无效 本文地址: http://blog.csdn.net/caroline_wendy Activity须要先在Manifest注冊,才干在app中使用; Manifest: ...

  10. Spring源码深度解析——笔记

    1.spring容器的基本用法 xml配置 <bean id="myTestBean" class="bean.MyTestBean"/> 调用 B ...