Problem Description
You are given N baskets of gold coins. The baskets are numbered from 1 to N. In all except one of the baskets, each gold coin weighs w grams. In the one exceptional basket, each gold coin weighs w-d grams. A wizard appears on the scene and takes 1 coin from Basket 1, 2 coins from Basket 2, and so on, up to and including N-1 coins from Basket N-1. He does not take any coins from Basket N. He weighs the selected coins and concludes which of the N baskets contains the lighter coins. Your mission is to emulate the wizard's computation.

 
Input
The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain four positive integers, separated by one blank space. The first three integers are, respectively, the numbers N, w, and d, as described above. The fourth integer is the result of weighing the selected coins.

N will be at least 2 and not more than 8000. The value of w will be at most 30. The value of d will be less than w.

 
Output
For each instance of the problem, your program will produce one line of output, consisting of one positive integer: the number of the basket that contains lighter coins than the other baskets.

 
Sample Input
10 25 8 1109
10 25 8 1045
8000 30 12 959879400
 
Sample Output
2
10
50
 

【题意】给出n个数的序列,求出给定区间的逆序数

【思路】N的范围比较小,先暴力搜出sum[1][1~n],

再就是sum[i][j]和sum[i-1][j]差得是a[i-1]对i~j的影响

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<string.h>
  4. using namespace std;
  5. const int N=+;
  6. int sum[N][N],a[N];
  7. int main()
  8. {
  9. int n,q;
  10. while(~scanf("%d%d",&n,&q))
  11. {
  12. memset(sum,,sizeof(sum));
  13. for(int i=; i<=n; i++)
  14. scanf("%d",&a[i]);
  15. for(int i=; i<=n; i++)
  16. {
  17. for(int j=; j<i; j++)
  18. {
  19. if(a[j]>a[i])
  20. sum[][i]++;
  21. }
  22. sum[][i]+=sum[][i-];
  23. }
  24. for(int i=; i<=n; i++)
  25. {
  26. int cnt=;
  27. for(int j=i; j<=n; j++)
  28. {
  29. if(a[i-]>a[j]) cnt--;
  30. sum[i][j]=sum[i-][j]+cnt;
  31. }
  32. }
  33. for(int i=; i<=q; i++)
  34. {
  35. int l,r;
  36. scanf("%d%d",&l,&r);
  37. printf("%d\n",sum[l][r]);
  38. }
  39. }
  40. return ;
  41. }

Baskets of Gold Coins_暴力的更多相关文章

  1. hdoj 2401 Baskets of Gold Coins

    Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)

    Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In ...

  3. Baskets of Gold Coins

    Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 6019:MG loves gold(暴力set)

    http://acm.hdu.edu.cn/showproblem.php?pid=6019 题意:给出n个颜色的物品,你每次取只能取连续的不同颜色的物品,问最少要取多少次. 思路:从头往后扫,用se ...

  5. 特殊篮子问题——C语言暴力破解

    You are given N baskets of gold coins. The baskets are numbered from 1 to N. In all except one of th ...

  6. OJ题解记录计划

    容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001  A+B Problem First AC: 2 ...

  7. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  8. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  9. NOIP 2002提高组 选数 dfs/暴力

    1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...

随机推荐

  1. hexo deploy出错的解决方法

    .ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...

  2. WordPress网站搭建

    . 1.进入 var/www/html中放入里的文件 2.. 安装http php php-sql [root@jw38 yum.repos.d]# systemctl restart httpd.s ...

  3. html/css小练习3

    效果图:

  4. JavaScript之Array类型

    1. 创建数组 var colors = new Array(); var colors = new Array(20); var colors = new Array("blue" ...

  5. UIKit框架

    在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...

  6. POJ 3278 Catch That Cow

    注:本人英语很渣,题目大意大多来自百度~=0= 题目大意 农民约翰需要抓住他的牛,他和他的牛在一条直线上(估计是一维生物),约翰在N (0 ≤ N ≤ 100,000)处,他的牛在 K (0 ≤ K ...

  7. V-MODEL指令实现方法

    V-MODEL 是VUE 的一个指令,在input 控件上使用时,可以实现双向绑定. 通过看文档,发现他不过是一个语法糖. 实际是通过下面的代码来实现的:   <%@ page language ...

  8. mybatis-generator-config工具的使用

    generator.xml <?xml version="1.0" encoding="UTF-8" ?>   <!DOCTYPE gener ...

  9. kendo模板 Uncaught Error: Invalid template:' 报错

    I was having a problem with a grid toolbar template because of a # in a hrefWorked out that I needed ...

  10. pthreads 2.0.10 test

    CentOS 6.3 cd /root mkdir pthreads //get php-5.6 and install zts version wget cn2.php.net/get/php-5. ...