摘要: 逆序数的定义:在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序。一个排列中逆序的总数就称为这个排列的逆序数。逆序数为偶数的排列称为偶排列;逆序数为奇数的排列称为奇排列。如2431中,21,43,41,31是逆序,逆序数是4,为偶排列。 --摘自百度百科记录数列的下标,按数列的值从小到大排序,所以后面插入的值肯定比前面的大,i - getsum(c[i].pos)就可以算出在i之前还有几个比c[i]大的数,累加就是答案#include <stdio.h>#include <stdlib.h>#include <stri 阅读全文
posted @ 2011-04-17 14:29 L.. 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 在 做ACM题时,经常都会遇到一些比较大的整数。而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-2^31,2^31),即-2147483648~2147483647。而unsigned范围是[0,2^32),即 0~4294967295。也就是说,常规的32位整数只能够处理40亿以下的数。那遇到比40亿要大的数怎么办呢?这时就要用到C++的64位扩展了。不同的编译器对64位整数的扩展有所不同。基于ACM的需要,下面仅介绍VC6.0与g++编译器的扩展。VCVC6.0 的64位整数分别叫做__int64与unsigned __int64,其范围分别是[-2^63, 2^6 阅读全文
posted @ 2011-04-16 21:14 L.. 阅读(802) 评论(0) 推荐(0) 编辑
摘要: 这题是模拟题...不要想复杂了哦 呵呵#include <stdio.h>#include <stdlib.h>struct Person{ int num; int b[9]; void init(){ num = 0; }};Person person[1001];int book[100001];void makeset(int n){ for(int i = 0; i <= n; ++i) book[i] = -1;}int main(){ int m, n, times; while(scanf("%d%d",&m, & 阅读全文
posted @ 2011-04-16 21:13 L.. 阅读(227) 评论(0) 推荐(0) 编辑
摘要: 题意不好理解啊..以下摘自discuss已知任意一个大于1的数可以表示成一些素数的乘积,即x=p1^e1*p2^e2…… pn^en (pi 为素数,ei 为对应素数的个数),现给你x的表示,要你求x-1的 表示。 例:输入:5 1 2 1 则x=5^1*2^1=10,所以x-1=9,9可以表示成:9=3^2 输出:3 2思路:反复试除#include <stdio.h>#include <string.h>#include <math.h>const int MAXN = 33333;int prime[MAXN],num;bool is[MAXN];in 阅读全文
posted @ 2011-04-12 21:27 L.. 阅读(360) 评论(0) 推荐(0) 编辑
摘要: /*RMQ问题——稀疏表算法状态转移方程dp[i,j]=min{dp[i,j-1],dp[i+2j-1,j-1]}*/#include <stdio.h>#include <math.h>#include <stdlib.h>const int MAXN = 50001;int max[MAXN][16],min[MAXN][16]; //2^16 = 65536int a[MAXN];int n, Q;inline int getMax(int a, int b){ return a > b ? a : b;}inline int getMin(in 阅读全文
posted @ 2011-04-12 17:09 L.. 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 单调队列 见http://www.cnblogs.com/lxf90/articles/2012016.html第一,原序列的坐标单调第二,原序列的值单调/*单调队列 */#include <stdio.h>using namespace std;const int MAXN = 100001;struct dqueue{ int val; int idx;}que[MAXN];int a[MAXN], cnt;int head, tail;int lefts;int main(){ int n; //cin >> n; scanf("%d",&am 阅读全文
posted @ 2011-04-12 17:04 L.. 阅读(166) 评论(0) 推荐(0) 编辑
摘要: inline bool scan_d(int &num) // 这个就是 加速的 关键了 { char in;bool IsN=false; in=getchar(); if(in==EOF) return false; while(in!='-'&&(in<'0'||in>'9')) in=getchar(); if(in=='-'){ IsN=true;num=0;} else num=in-'0'; while(in=getchar(),in>='0' 阅读全文
posted @ 2011-04-12 16:17 L.. 阅读(146) 评论(0) 推荐(0) 编辑
摘要: /*做这题的时候是参考别人的程序现在拿出来回顾下好好理解一下这题的思路第一,这题需要离散化第二,计算矩形并的面积 当某一条线段被覆盖两次或两次以上 计算一次面积 具体的画个图比较明了第三,也是最重要的,线段数once, more的更新, 当时没有掌握到线段数的精髓 也是迷迷糊糊的,现在回来想想,once more 是第一类信息 表示当前区间的性质所有递归回来的时候 由递推关系更新once more 而more 又是由once 推出来的 */#include <stdio.h>#include <stdlib.h>#include <math.h>#defin 阅读全文
posted @ 2011-04-12 16:03 L.. 阅读(984) 评论(1) 推荐(0) 编辑
摘要: /*按照大牛博客顺序做的题目 以前离散化好好理解了下注意离散化后struct SegTree{ int l, r; int color; int getMid(){ return (l + r) >> 1; }}tree[MAXN << 2];中l,r不是原区间的坐标了,而是排序去重后数组中对应的下标做这题问题不大 基本上1A 第一次数组开小了 囧.*/#include <stdio.h>#include <stdlib.h>#include <string.h>#define L(x) ((x) << 1)#define 阅读全文
posted @ 2011-04-12 14:33 L.. 阅读(203) 评论(0) 推荐(0) 编辑
摘要: /*哈希第一题啊..! 谢谢 http://www.cnblogs.com/Dario67/archive/2011/04/09/2010724.html 的博主这题投机取巧了,判断是否相等 直接排序 比较相等 混过去了 实际题目意思不是这样的 呵呵*/#include <stdio.h>#include <stdlib.h>#define M 99991 //大素数 这是怎么来的我还不清楚#define MAXN 100000struct flake{ int arm[6]; struct flake *next; //拉链法处理冲突 void init(){ nex 阅读全文
posted @ 2011-04-12 06:09 L.. 阅读(345) 评论(0) 推荐(0) 编辑