上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 22 下一页
摘要: 思路:这题的处理方式和hdu4358有点像。我们用一个pre[x]表示约数x的倍数上次出现的位置,将查询按区间的右节点升序排序。num[i]的约数为j,如果pre[j]为0,就将pre[j]置为i;否则就update(pre[j],j),表示的意思是约数j肯定不是第一次出现,将pre[j]以前的区间更新最大约数。如果查询区间的右边界在i处,那么左边界在pre[j]以前就肯定就能取到j。因为num[pre[j]]和num[i]有一个公共约数j,且pre[j]和i被该查询区间所覆盖。#include#include#include#include#define Maxn 50010#define 阅读全文
posted @ 2013-07-31 17:59 fangguo 阅读(401) 评论(0) 推荐(1) 编辑
摘要: 思路:从后面往前面插,用一个二维树状数组保存,c[i][0]表示比i小的元素和,c[i][1]表示比i小的元素个数。#include#include#include#include#define Maxn 100010#define lowbit(x) (x&(-x))using namespace std;__int64 C[Maxn][2],n,num[Maxn],cnt;__int64 Sum(__int64 pos){ __int64 sum=0; while(pos) { sum+=C[pos][0]; cnt+=C[pos][1]; ... 阅读全文
posted @ 2013-07-31 10:16 fangguo 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 思路:加一个数e就用update(e,1)。删除元素e就用update(e,-1)。找比a大的第k大的元素就用二分查找。#include#include#include#include#define Maxn 120010#define lowbit(x) (x&(-x))using namespace std;int C[Maxn];int Sum(int pos){ int sum=0; while(pos) { sum+=C[pos]; pos-=lowbit(pos); } return sum;}void update(int... 阅读全文
posted @ 2013-07-31 09:23 fangguo 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 思路:我们只需坚守一个原则,本来就在左边的坚决不把它换到右边。也就是相邻的两个数,左边小,右边大,那么就不调换。这样对每个数,只要统计左边比它大的数的个数。可以从后面开始用树状数组统计比它小的数的个数是一样的。#include#include#include#include#define Maxn 1000010#define lowbit(x) (x&(-x))using namespace std;int C[Maxn],num[Maxn],n,r[Maxn];void init(){ memset(C,0,sizeof(C));}int cmp(int a,int b){ r.. 阅读全文
posted @ 2013-07-30 20:52 fangguo 阅读(256) 评论(0) 推荐(0) 编辑
摘要: 思路:从后面往前面统计,每次先sum+=Sum(num[i]+1),然后在update(num[i]+1,1)。这样每次Sum每次加的个数就是num[i]的逆序对个数。每次从队首调一个元素到队尾,逆序对的变化为sum=sum-num[i]+n-num[i]+1。减少的个数为num[i],增加的个数为n-num[i]-1。#include#include#include#include#define Maxn 5010#define lowbit(x) (x&(-x))using namespace std;int C[Maxn],num[Maxn],n;void init(){ mem 阅读全文
posted @ 2013-07-30 20:02 fangguo 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 这题对于O(n^2)的算法有很多,我这随便贴一个烂的,跑了375ms。#include#includeusing namespace std;int mat[8008];int main(){ int i,j,t,n; scanf("%d",&n); mat[0]=1; for(i=1;i=mat[i]) { mat[j]++;} } for(i=0;i#include#include#include#include#define Maxn 8010#define inf 0x7... 阅读全文
posted @ 2013-07-30 15:46 fangguo 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 思路:先有每个儿子向所有他喜欢的姑娘建边,对于最后给出的正确匹配,我们建由姑娘到相应王子的边。和某个王子在同一强连通分量,且王子喜欢的姑娘都是该王子能娶得。思想类似匈牙利算法求匹配的时候,总能找到增广路径。代码比较烂,跑了近6s。#include#include#include#include#include#include#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a) q[Maxn];void init(){ memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); ... 阅读全文
posted @ 2013-07-30 15:34 fangguo 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 直接写个RMQ就能过。#include#include#include#include#include#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))#define Maxn 60010using namespace std;int maxnum[Maxn][20],minnum[Maxn][20],n,Log[Maxn+10];int Log2(int x){ int num=0; x/=2; while(x) { num++; x/=2; } ... 阅读全文
posted @ 2013-07-29 20:14 fangguo 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 思路:我们需要判断是否有满足的a[n],其实也就是对每一个二进制位进行判断,看是否有满足的。那么我们每次取出一个二进制位,这样每一位只有0,1两种状态,就成了比较典型的2-SAT问题了。#include#include#include#include#include#define Maxn 1010#define Maxm Maxn*Maxnusing namespace std;int vi[Maxn],head[Maxn],dfn[Maxn],low[Maxn],e,n,lab,top,num,m,id[Maxn],Stack[Maxn],B[510][510];struct Edge{ 阅读全文
posted @ 2013-07-29 16:44 fangguo 阅读(238) 评论(0) 推荐(0) 编辑
摘要: 思路:就是找能走的走,遍历一边所有情况,满足就退出。Accepted4284328MS2280K2239 BC++//#pragma comment(linker, "/STACK:1024000000,1024000000")#include #include #include #include #include #include #define Maxn 110#define Maxm 6000#define LL int#define inf 100000000#define Abs(a) (a)>0?(a):(-a)using namespace std;in 阅读全文
posted @ 2013-07-29 14:42 fangguo 阅读(241) 评论(0) 推荐(0) 编辑
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 22 下一页