上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 26 下一页
摘要: 这个题目的证明挺美的;把分金币问题变成了一个数轴上点的距离问题;代码: 1 #include 2 #include 3 #define ll long long 4 #define maxn 1000009 5 using namespace std; 6 7 ll a[maxn],b[maxn],sum,m; 8 9 int main()10 {11 int n;12 while(scanf("%d",&n)!=EOF)13 {14 sum=0;15 for(int i=0;i<n;i++){scanf("%lld",&a[i]) 阅读全文
posted @ 2013-10-25 13:12 Yours1103 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 水题怡情 1 #include 2 #include 3 #define maxn 1005 4 using namespace std; 5 struct war 6 { 7 int a,b; 8 bool operatort.b;11 }12 }wa[maxn];13 14 int main()15 {16 int n,ca=1;17 while(scanf("%d",&n)&&n)18 {19 for(int i=0;i<n;i++)scanf("%d%d",&wa[i].a,&wa[i].b);20 阅读全文
posted @ 2013-10-25 13:00 Yours1103 阅读(138) 评论(0) 推荐(0) 编辑
摘要: 做一两个水题怡情一下! 1 #include 2 #include 3 #define maxn 20009 4 using namespace std; 5 int a[maxn],b[maxn]; 6 7 int main() 8 { 9 int n,m;10 while(scanf("%d%d",&n,&m)&&(n+m))11 {12 for(int i=0;im){puts("Loowater is doomed!");continue;}15 sort(a,a+n);16 sort(b,b+m);17 ... 阅读全文
posted @ 2013-10-25 12:47 Yours1103 阅读(113) 评论(0) 推荐(0) 编辑
摘要: RMQ问题;采用游程编码;代码: 1 #include 2 #include 3 #include 4 #define maxn 100009 5 using namespace std; 6 7 int d[maxn][30],value[maxn],cnt[maxn],num[maxn],left[maxn],right[maxn]; 8 9 void RMQ_init(int n)10 {11 for(int i=1; ir)return 0;20 int k=0;21 while(1<<(k+1)<=r-l+1)k++;22 return max(d... 阅读全文
posted @ 2013-10-24 20:58 Yours1103 阅读(240) 评论(0) 推荐(0) 编辑
摘要: 树状数组,把他们的技能值作为轴;首先按照编号从小到大插入值,这样就可以得到,技能值比当前小的人数;然后按照编号从大到小再插一遍;代码: 1 #include 2 #include 3 #define maxn 20005 4 using namespace std; 5 6 int a[maxn],c[100010]; 7 int l[maxn],r[maxn]; 8 int lowbit(int x){return x&-x;} 9 void add(int x,int d){while(x0){ret+=c[x],x-=lowbit(x);}14 return ret;15 }1. 阅读全文
posted @ 2013-10-24 18:45 Yours1103 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 用两个优先队列来实现,因为队列只能从一头出去;所以维护一个数组,来标记这个队列的已经出列而另外一个队列没有出列的元素;到时候再把他们删了就行; 1 #include 2 #include 3 #include 4 #define maxn 1000009 5 using namespace std; 6 7 priority_queue,greater >gq; 8 priority_queue,less >lq; 9 int numg[maxn],numl[maxn];10 int main()11 {12 int n,x,k;13 while(scanf("%d&qu 阅读全文
posted @ 2013-10-24 17:28 Yours1103 阅读(200) 评论(0) 推荐(0) 编辑
摘要: 链表的应用;le[i]表示第i个元素左边的那个元素的标号;ri[i]表示第i个元素右边的那个元素的标号;代码: 1 #include 2 #include 3 #define maxn 100009 4 using namespace std; 5 6 char s[maxn]; 7 int le[maxn],ri[maxn]; 8 9 int main()10 {11 while(gets(s+1)!=NULL)12 {13 le[0]=ri[0]=0;14 for(int i=1; s[i]; i++)15 {16 ... 阅读全文
posted @ 2013-10-24 16:43 Yours1103 阅读(232) 评论(0) 推荐(0) 编辑
摘要: 带权值的并查集的应用;代码: 1 #include 2 #include 3 #include 4 #include 5 #define maxn 20005 6 using namespace std; 7 8 int f[maxn]; 9 int d[maxn];10 int t,n,x,y;11 char s[5];12 13 int find(int x)14 {15 if(f[x]!=x)16 {17 int r=find(f[x]);18 d[x]+=d[f[x]];19 return f[x]=r;20 }... 阅读全文
posted @ 2013-10-24 12:35 Yours1103 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 并查集的简单应用:代码: 1 #include 2 #define maxn 100005 3 using namespace std; 4 int f[maxn]; 5 int find(int x){return x==f[x]?x:f[x]=find(f[x]);} 6 int main() 7 { 8 int x,y; 9 while(scanf("%d",&x)!=EOF)10 {11 for(int i=0;i<maxn;i++)f[i]=i;12 int cnt=0;13 while(x!=-1)14 ... 阅读全文
posted @ 2013-10-24 10:50 Yours1103 阅读(120) 评论(0) 推荐(0) 编辑
摘要: 多路并归问题:代码: 1 #include 2 #include 3 #include 4 #define maxn 760 5 using namespace std; 6 7 struct node 8 { 9 int s,b;10 node(int s,int b):s(s),b(b) {}11 bool operatort.s;14 }15 };16 17 void merge(int *a,int *b,int *c,int n)18 {19 priority_queueq;20 for(int i=0; i<n; i++)21 ... 阅读全文
posted @ 2013-10-24 10:13 Yours1103 阅读(188) 评论(0) 推荐(0) 编辑
上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 26 下一页