Baskets of Gold 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.
10 25 8 1045
8000 30 12 959879400
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_暴力的更多相关文章
- hdoj 2401 Baskets of Gold Coins
Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 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 ...
- Baskets of Gold Coins
Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 6019:MG loves gold(暴力set)
http://acm.hdu.edu.cn/showproblem.php?pid=6019 题意:给出n个颜色的物品,你每次取只能取连续的不同颜色的物品,问最少要取多少次. 思路:从头往后扫,用se ...
- 特殊篮子问题——C语言暴力破解
You are given N baskets of gold coins. The baskets are numbered from 1 to N. In all except one of th ...
- OJ题解记录计划
容错声明: ①题目选自https://acm.ecnu.edu.cn/,不再检查题目删改情况 ②所有代码仅代表个人AC提交,不保证解法无误 E0001 A+B Problem First AC: 2 ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- NOIP 2002提高组 选数 dfs/暴力
1008 选数 2002年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 已知 n 个整数 x1,x2,…, ...
随机推荐
- js 判断是什么类型浏览器
// firefoxif ( window.sidebar && "object" == typeof( window.sidebar ) && ...
- 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 ...
- SQL server同时删除多个表
) while exists (select name from sys.tables where name like 'se_%') begin @varname = name from sys.t ...
- CheckLogin
# encoding: utf-8 # Creator:耿亚月 Creation time:2017-1-1 # Modifier:耿亚月 Modification time:2017-1-2 #fi ...
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(完)
前言 这一篇是本系列的最后一篇,虽然示例讲到这里就停止呢,但对于这些技术的学习远不能停止.虽然本示例讲的比较基础,但是正如我第一篇说到的,这个系列的目的不是说一些高端的架构设计,而是作为一个入门级,对 ...
- P53 T3
为方便旅客,某航空公司拟开发一个机票预定系统.旅行社把预定机票的旅客信息(姓名.性别.工作单位.身份证号码.旅行时间.旅行目的地等)输入进入该系统,系统为旅客安排航班,印出取票通知和账单,旅客在飞机起 ...
- 关于silverlight5 打印功能收集
http://www.cnblogs.com/slmk/archive/2012/07/18/2570303.html Silverlight打印解决方案2.1正式发布(支持打印预览.页面设置(横向纵 ...
- BroadCast Receiver的使用
定义 广播接收器分为标准广播和有序广播,标准广播是异步执行的广播,有序广播是同步执行的,同一时刻只有一个广播接收器会收到广播,执行结束后,广播才会继续传递. 静态注册 在Androidmanifest ...
- TortoiseSVN文件夹及文件图标不显示解决方法
由于自己的电脑是win7(64位)的,系统安装TortoiseSVN之后,其他的功能都能正常的使用,但是就是文件夹或文件夹的左下角就是不显示图标,这个问题前一段时间就遇到了(那个时 ...
- SQL SERVER 字符串常用函数
在开发T-SQL时,经常会需要对字符串进行各种各样的操作,下面介绍常用的字符串函数. 1.获取字符的ASCII码 ASCII ASCII码是对字符的标准编码.要获取字符的ASCII码就可以通过调用AS ...