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,…, ...
随机推荐
- hexo deploy出错的解决方法
.ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...
- WordPress网站搭建
. 1.进入 var/www/html中放入里的文件 2.. 安装http php php-sql [root@jw38 yum.repos.d]# systemctl restart httpd.s ...
- html/css小练习3
效果图:
- JavaScript之Array类型
1. 创建数组 var colors = new Array(); var colors = new Array(20); var colors = new Array("blue" ...
- UIKit框架
在今后的应用程序构建中,会陆续使用各式各样的控件,因此UIKit框架的引入是必不可少的! 一.简介 UIKitk框架提供一系列的Class(类)来建立和管理iPhone OS应用程序的用户界面接口.应 ...
- POJ 3278 Catch That Cow
注:本人英语很渣,题目大意大多来自百度~=0= 题目大意 农民约翰需要抓住他的牛,他和他的牛在一条直线上(估计是一维生物),约翰在N (0 ≤ N ≤ 100,000)处,他的牛在 K (0 ≤ K ...
- V-MODEL指令实现方法
V-MODEL 是VUE 的一个指令,在input 控件上使用时,可以实现双向绑定. 通过看文档,发现他不过是一个语法糖. 实际是通过下面的代码来实现的: <%@ page language ...
- mybatis-generator-config工具的使用
generator.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE gener ...
- 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 ...
- 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. ...