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,…, ...
随机推荐
- python【0】-目录
python[1]-基础知识 Python[2]-列表和元组 Python[3]-字典dic和集合set python[4]-函数 python[5]-生成式,生成器 python[6]-函数式编程 ...
- Centos7 hostname重启失效
/etc/hosts 文件如下 [root@god ~]# more /etc/hosts 127.0.0.1 localhost ::1 localhost localhost.localdoma ...
- phpMyAdmin - 错误 您应升级到 MySQL 5.5.0 或更高版本,解决办法。。。
折腾自己的个人网站,装了个数据库管理工具,遇到您应升级到 MySQL 5.5.0 或更高版本... 采用降级phpmyadmin版本的方法解决了: 查找phpmyadmin/libraries/com ...
- 第五次Java作业
作业一: 文件显示列表框. 增加了下拉式组合框,text区域设置颜色为红色. import javax.swing.*; import java.awt.*; import java.io.File; ...
- Android基础:startActivityForResult 和 onActivityResult 问题
项目中用到弹出Acitivity来获得用户输入 所以用到 onActivityResult()方法接受用户输入 奇怪问题 startActivityForResult() 后直接调用 onActivi ...
- My Game --文件读取数据
My Game --线段数据 中说到背景的绘制由贝赛尔曲线生成线段,用 DrawNode 画多边形,同时一张背景有两座山,一座山有两条以上贝赛尔曲线保存,用了嵌套的数据类:Bezier,LineLay ...
- Swift介绍
Swift介绍 Swift介绍 Swift发布于2014年wwdc大会,是苹果推出的一门编程语言,刚推出的时候主要在os X和iOS平台,今年wwdc大会上,苹果公司宣布今年年底Swift将会开源,开 ...
- flume从kafka中读取数据
a1.sources = r1 a1.sinks = k1 a1.channels = c1 #使用内置kafka source a1.sources.r1.type = org.apache.flu ...
- oracle中dual的使用
dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情,如下:1.查看当前用户,可以在 SQL Plus中执行下面语句select ...
- UDP丢包严重
项目要求udp能够达到10万的并发量,搞了几天,丢包严重, 今天终于解决了,原来是socket缓冲区设置的不够大已经jvm内存不够大