随笔分类 - 树状数组
摘要:题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1400结构体排序+树状数组模板..#include#include#includeusing namespace std;int c[100009];struct point{ int x; int v;} p[100000];bool cmp(point p1,point p2){ if(p1.x !=p2.x) return p1.x>p2.x; else return p1.v0)...
阅读全文
摘要:题目链接:http://poj.org/problem?id=3928乒乓比赛,有N个人参加,输入每个玩家的技能等级,对每个人设置一个特定ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛。参考的其他人的代码,重新敲了一遍。/*POJ 3928Ping pong*/#include#include#includeusing namespace std;#define N 23000int c[N],n;long long int ans;struct Node{ int id; int lev...
阅读全文
摘要:题目链接:http://poj.org/problem?id=2299用了树状数组,求逆序数。读入这些数,每读一个数就update一次,看一下它前面比它小的已出现过的有多少个sum(),然后用当前的位置-当前的sum(),就可以得到当前逆序对数了,加起来就得到总的逆序对数。#include#include#includeusing namespace std;#define N 500010int n,c[N],reflect[N];struct Node{ int val; int pos;} node[N];bool cmp(Node a,Node b){ return ...
阅读全文
摘要:题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=1867每次更新时判断是否素数,如果从非素数变成素数就Update(x, 1),如果从素数变成非素数就Update(x, -1)。 1 /*HIT 1867 2 经理的烦恼 3 */ 4 #include 5 #include 6 const int N=1000009; 7 8 int a[N],c[N],n,m,C; 9 int prime(int num)10 {11 int i;12 if(num0)37 {38 s += c[num];39 ...
阅读全文
摘要:Mobile phonesTime Limit: 5000MSMemory Limit: 65536KTotal Submissions: 13774Accepted: 6393DescriptionSuppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows and columns numbe
阅读全文

浙公网安备 33010602011771号