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. VS2015快捷键

    Shift+Alt+Enter: 切换全屏编辑 Ctrl+B,T / Ctrl+K,K: 切换书签开关Ctrl+B,N / Ctrl+K,N: 移动到下一书签Ctrl+B,P: 移动到上一书签Ctrl ...

  2. PHP语言基础简单整理

    1.开始结束标记<? ... ?> 2.定义变量:$变量名 例: $str="锦清笋";不需要指明数据类型 3.输出语句:(1)echo "hello wor ...

  3. java 配置环境变量

    使用java编程首先需要安装jdk,然后还需要给你的电脑配置环境变量,下面就用图文演示如何配置环境变量: 1.右键我的电脑 -> 属性 2.点击“高级系统设置” 3.点击“环境变量” 4.在系统 ...

  4. ByteArrayBuilder

    public class ByteArrayBuilder : IDisposable { #region Constants /// <summary> /// True in a by ...

  5. 011-Scala中的apply实战详解

    011-Scala中的apply实战详解 object中的apply方法 class中的apply方法 使用方法 apply方法可以应用在类或者Object对象中 class类 必须要创建实例化的类对 ...

  6. http 301和302的区别

    1.什么是301转向?什么是301重定向? 301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种, ...

  7. 扩展django的User的部分方法

    这做项目时发现django自带的User中的字段不够用,默认的auth_user表总共只有11个字段,如果需要更多的字段该怎么办,在网上搜了一下,有这么几种方法. 1. 直接修改django 源码,修 ...

  8. linux下删除文件夹的命令

    使用rm -rf 目录名字 命令即可 -r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思 eg 删除文件夹实例:rm -rf /var/log/httpd/acc ...

  9. HTMlhleper

    @{ ViewBag.Title = "Index";} <h2>Index</h2> <div> @{ int id=12121; var I ...

  10. intellij idea 初步环境熟悉

    刚进来天渔项目组,连开发环境都是新的,学习至上 so 从eclipse过度过来还是有段时间的,期间虽然懵懂,但是也要坚持不耻下问 好了一下是idea的官网http://confluence.jetbr ...