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,…, ...
随机推荐
- clearfix清除浮动
首先在很多很多年以前我们常用的清除浮动是这样的. 1 .clear{clear:both;line-height:0;} 现在可能还可以在很多老的站点上可以看到这样的代码,相当暴力有效的解决浮动的问题 ...
- Sql:多行合并一行以及多条数据取时间最早的那条
有两个导数据的需求,1.一张表里面每一个订单号可能对应多条数据,每个单号返回时间最早的那条. 2.根据条件查询某个字段并按照逗号,合并在一起. 表类似结构如下: 第一条sql:select c.Id, ...
- 利用jQueryRotate旋转插件开发大转盘抽奖
前言: 公司原来开发大转盘抽奖活动用的是flash 我发现swf文件竟然有6m大,吓尿了! 其实完全可以用js写的,但是自身前端功力有限,且时间紧迫,所以直接用旋转插件就好,兼容各方面都可以保证. 1 ...
- jquery性能
1. 使用最新版本的jQuery jQuery的版本更新很快,你应该总是使用最新的版本.因为新版本会改进性能,还有很多新功能. 下面就来看看,不同版本的jQuery性能差异有多大.这里是三条最常见的j ...
- 2014中国黑客榜(beta版)
黑客,英文hacker.精通计算机各类技术的计算机高手,泛指擅长IT技术的人群.计算机科学家. 最近受某机构所托搜集国内活跃黑客近况.本着客观专业,权威可信的原则参考了国内从00年到最新的黑客榜单,以 ...
- window 链接方式
一.硬链接 mklink /H <destination> <source> 创建后的图标也和原文件的图标一样,在属性中也无法看出其中的链接关系 可通过命令查看 fsutil ...
- centos下在线安装mysql
1 首先查看是否有安装过,如果已经安装过,就不必再安装了 yum list installed mysql* rpm -qa | grep mysql* 2 查看有没有安装包: yum list my ...
- WebService 生成类的命令语句
在开发项目中,有时候需要调用webservice接口程序,根据项目规定有的项目是直接引入接口,有的是需要把接口生成代理类的形式在项目中使用,根据项目需要来取舍. 以下列出项目中常用的Webservic ...
- 总结-css编码规范
一.注释 统一采用 :/* 注释内容 */ 二.命名 1.常用命名(多查单词) 参考命名规范.doc 2.选择器 1> [建议] 选择器的嵌套层级应不大于 3 级,位置靠后的限定条件应尽可能精确 ...
- 使用javascript打开一个新页而不被浏览器屏蔽
使用javascript打开一个新页面可以有几种方式,但各有利弊,以下做下分析 1.window.open(url) 这是新手最常用的方法,好处是简单易用,坏处,很简单,会被很多浏览器拦截而导致功能失 ...