摘要: 二维树状数组#include #include using namespace std;#define N 1005int c[N][N];int i,j,n,num,p,T,cnt=1;int sum(int x,int y){ int i,j,tmp=0; for(i=x;i>0;i-=(i&-i)) for(j=y;j>0;j-=(j&-j)) tmp+=c[i][j]; return tmp;}void add(int x,int y,int num){ for(int i=x;i'9'||c='0')x=x*10+c- 阅读全文
posted @ 2014-02-23 20:51 forever97 阅读(271) 评论(0) 推荐(0) 编辑
摘要: 题解:如图,哈夫曼编码,不断选取规模最小的两个连接,如样例AAAAABCD,A规模为5,B规模为1,C规模为1,D规模为1,那么A取0,BCD为10,110,111时编码长度最短,那么就是C与D先合并,如图中1,2节点,变为规模为2的点,然后与B(3)相连,最后和A(4)连接。其实题目不需要建立哈夫... 阅读全文
posted @ 2014-02-23 16:52 forever97 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 题目大意:给定一些正方体的关系,要求一组符合这些关系的正方体坐标,如果不存在符合条件的正方体坐标,IMPOSSIBLE。(Special Judge)实力还是太弱了,完全不会……#include #include #include #define MAXN 2010#define MAXR 500000#define MAX 999999typedef struct edges{ int v,w,next;}edge;int N, R;edge edge_X[MAXR], edge_Y[MAXR], edge_Z[MAXR];int s_X[MAXN], s_Y[MAXN], s_Z[... 阅读全文
posted @ 2014-02-23 15:16 forever97 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 题解:利用set的判重功能,直接计算出现的字符串数量,同时记录失败的字符串,如果两者相差1,则有冠军,否则没有:#include #include #include using namespace std;int main(){ int n; while(scanf("%d",&n),n){ getchar(); string a,b; set sum; set fail; for(int i=0;i>a>>b; sum.insert(a); sum.insert(b)... 阅读全文
posted @ 2014-02-23 14:58 forever97 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 题解:裸的topo,注意判重,由于数据升序所以免排序。#include #include using namespace std;#define N 505int map[N][N],n,m,a,b,in[N],ans[N];void topo(){ int top=0,i; memset(ans,0,sizeof ans); while(true){ for(i=1;i<=n;i++)if(in[i]==0)break; if(i==n+1)return; in[i]=-1; ans[top++]=i; ... 阅读全文
posted @ 2014-02-23 14:41 forever97 阅读(149) 评论(0) 推荐(0) 编辑
摘要: map……#include #include #include using namespace std;mapmap1;mapmap2;int main(){ string s,secret,usage,tmp; getline(cin,s); while(s!="@END@"){ int find=s.find(']'); secret=s.substr(0,find+1); usage=s.substr(find+2,s.size()-find-2); map1[usage]=secret; ma... 阅读全文
posted @ 2014-02-23 14:18 forever97 阅读(216) 评论(0) 推荐(0) 编辑