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的影响

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=+;
int sum[N][N],a[N];
int main()
{
int n,q;
while(~scanf("%d%d",&n,&q))
{
memset(sum,,sizeof(sum));
for(int i=; i<=n; i++)
scanf("%d",&a[i]);
for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{
if(a[j]>a[i])
sum[][i]++;
}
sum[][i]+=sum[][i-];
}
for(int i=; i<=n; i++)
{
int cnt=;
for(int j=i; j<=n; j++)
{
if(a[i-]>a[j]) cnt--;
sum[i][j]=sum[i-][j]+cnt;
}
}
for(int i=; i<=q; i++)
{
int l,r;
scanf("%d%d",&l,&r);
printf("%d\n",sum[l][r]);
}
}
return ;
}

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. js 判断是什么类型浏览器

    //  firefoxif ( window.sidebar && "object" == typeof( window.sidebar ) && ...

  2. MYSQL5.7版本sql_mode=only_full_group_by问题

    具体出错提示: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggr ...

  3. SQL server同时删除多个表

    ) while exists (select name from sys.tables where name like 'se_%') begin @varname = name from sys.t ...

  4. CheckLogin

    # encoding: utf-8 # Creator:耿亚月 Creation time:2017-1-1 # Modifier:耿亚月 Modification time:2017-1-2 #fi ...

  5. EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(完)

    前言 这一篇是本系列的最后一篇,虽然示例讲到这里就停止呢,但对于这些技术的学习远不能停止.虽然本示例讲的比较基础,但是正如我第一篇说到的,这个系列的目的不是说一些高端的架构设计,而是作为一个入门级,对 ...

  6. P53 T3

    为方便旅客,某航空公司拟开发一个机票预定系统.旅行社把预定机票的旅客信息(姓名.性别.工作单位.身份证号码.旅行时间.旅行目的地等)输入进入该系统,系统为旅客安排航班,印出取票通知和账单,旅客在飞机起 ...

  7. 关于silverlight5 打印功能收集

    http://www.cnblogs.com/slmk/archive/2012/07/18/2570303.html Silverlight打印解决方案2.1正式发布(支持打印预览.页面设置(横向纵 ...

  8. BroadCast Receiver的使用

    定义 广播接收器分为标准广播和有序广播,标准广播是异步执行的广播,有序广播是同步执行的,同一时刻只有一个广播接收器会收到广播,执行结束后,广播才会继续传递. 静态注册 在Androidmanifest ...

  9. TortoiseSVN文件夹及文件图标不显示解决方法

              由于自己的电脑是win7(64位)的,系统安装TortoiseSVN之后,其他的功能都能正常的使用,但是就是文件夹或文件夹的左下角就是不显示图标,这个问题前一段时间就遇到了(那个时 ...

  10. SQL SERVER 字符串常用函数

    在开发T-SQL时,经常会需要对字符串进行各种各样的操作,下面介绍常用的字符串函数. 1.获取字符的ASCII码 ASCII ASCII码是对字符的标准编码.要获取字符的ASCII码就可以通过调用AS ...