关键词:
题意:给出所有人比的场数,设计一种方案。赢的人必须连续打下一轮。
能得知2个结论:1:不会有人的场数超过场数和的一半,否则他的对手会有自己。2:要打赢一个人的人至少会打2场,因为他打赢算1场,然后还必须参加下一场。打2场以上的人打的场数和>=所有人的场数和的一半。
这样的话,就用场数多的当胜者,他打的最后一场让他败,换另一个胜场多的当胜者。
实际实现有点困难。特别注意对手不能是自己。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #define mkp make_pair using namespace std; const double EPS=1e-8; const int SZ=10050,INF=0x7FFFFFFF; typedef long long lon; priority_queue<pair<int,int>> pq; int arr[SZ][2]; void work(int n) pair<int,int> top=pq.top(); pq.pop(); for(int i=1;i<=top.first-1;++i)arr[i][0]=top.second; arr[top.first][1]=top.second; int pos=top.first; if(pos==n)++pos; for(;pos!=n+1;) top=pq.top(); pq.pop(); for(;top.first&&pos!=n+1;--top.first) //cout<<pos<<endl; //if(!arr[pos][1])arr[pos++][1]=top.second; if(top.first==1) arr[pos][1]=top.second; if(pos==n)++pos; else arr[pos++][0]=top.second; pos=1; if(top.first) for(;top.first;) if(arr[pos][0]==0)arr[pos++][0]=top.second,--top.first; else if(arr[pos][1])++pos; else arr[pos++][1]=top.second,--top.first; for(;!pq.empty();) top=pq.top(); pq.pop(); for(;top.first;) if(arr[pos][0]==0)arr[pos++][0]=top.second,--top.first; else if(arr[pos][1])++pos; else arr[pos++][1]=top.second,--top.first; int main() std::ios::sync_with_stdio(0); //freopen("d:\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) int n; cin>>n; int sum=0; for(int i=1;i<=n;++i) int tmp; cin>>tmp; pq.push(mkp(tmp,i)); sum+=tmp; sum/=2; work(sum); cout<<sum<<endl; for(int i=1;i<=sum;++i) cout<<arr[i][0]<<" "<<arr[i][1]<<endl; return 0;
sgu104littleshopofflowers(dp)(代码片段)
104.Littleshopofflowerstimelimitpertest:0.25sec. memorylimitpertest:4096KBPROBLEMYouwanttoarrangethewindowofyourflowershopinamostpleasantway.Youhave F bunchesofflowers,eachbeingofadifferentkind,andatl 查看详情
今日sgu(代码片段)
SGU100题意:普通的a+b#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<<"";#definerep(i,a,b)for(inti=a;i<(b);++i 查看详情
今日sgu5.14(代码片段)
//SGU131还没完全想清楚留坑SGU259题意:一个机器处理n个任务,每个任务有时间t和传送时间l收获:贪心#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<<"" 查看详情
sgu282isomorphism(代码片段)
?????????rip ????????? ?????? ?????? ????????? ?????? put mat ge 查看详情
sgu-203hyperhuffman(哈夫曼编码)(代码片段)
HyperhuffmanYoumighthaveheardaboutHuffmanencoding-thatisthecodingsystemthatminimizestheexpectedlengthofthetextifthecodesforcharactersarerequiredtoconsistofanintegralnumberofbits.Letusrecallcodesassign 查看详情
sgu---102欧拉函数(代码片段)
题目链接:https://cn.vjudge.net/problem/SGU-102#author=0题目大意:求解小于等于N的且与N互质的数字有多少个解题思路:直接求欧拉函数即可关于欧拉函数的知识:传送门 这里可以直接暴力,但是如果不会欧拉函数单个求,打表求的... 查看详情
sgu169numbers数学(代码片段)
169.NumbersLetuscallP(n)-theproductofalldigitsofnumbern(indecimalnotation). Forexample,P(1243)=1*2*4*3=24;P(198501243)=0. Letuscallntobeagoodnumber,if(p(n)<>0)and(nmodP(n)=0). Let 查看详情
今日sgu5.15(代码片段)
...一行转移过来,因为上一行,那么最多有7情况,详情看代码#include<bits/stdc++.h>#definede(x)cout<<#x< 查看详情
今日sgu5.20(代码片段)
SGU404题意:。。收获:取模#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<<"";#definerep(i,a,b)for(inti=a;i<(b);++ 查看详情
今日sgu5.22(代码片段)
SGU296题意:给你一个最多1000位的数,让你删除k位使得剩下的数最大收获:贪心#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<<"";#definerep(i, 查看详情
今日sgu5.19(代码片段)
SGU142题意:给你一个长度为n的串(由a,b组成),让你找出一个串不是n的子串,长度最下收获:思维题,思路在代码里#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<< 查看详情
今日sgu5.29(代码片段)
sgu299题意:给你n个线段,然后问你能不能选出其中三个组成一个三角形,数字很大收获:另一个大整数模板#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<<"";#de 查看详情
今日sgu5.12(代码片段)
SGU149题意:求每一个点的距离最远距离的点的长度收获:次大值和最大值,dfs#include<bits/stdc++.h>#definede(x)cout<<#x<<"="<<x<<endl;#definedd(x)cout<<#x<<"="<<x<<"";#definerep(i,a, 查看详情
sgu179bracketslight(代码片段)
题意:假设‘(‘<‘)‘,给出一个匹配的串,问下一个匹配的串。看标程输出的结果很久才发现转换机制。从右边开始,忽略长度为2的()子串。1.如果右边有‘()‘子串:找到第一个(,换成‘)‘(1).如果新产生了单独的‘... 查看详情
sgu170particles(代码片段)
题意:一个串变为另一个串要移动的次数。串中相对位置相同的移过去就行。#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<vector>#include<iomanip>#include<cstring>#inclu 查看详情
sgu154(代码片段)
Factorial题意:能否找到一个数,它的阶乘后面0的个数为n?数越大,阶乘后的0越多。用二分找。对于一个数x,它的阶乘,将小于等于它的数分解质因数。其中2的个数一定大于5的个数。因此计5的个数就是结果末尾0的个数。比它小... 查看详情
今日sgu5.(代码片段)
SGU122题意:给你n个人,每个人有大于N/2(向上取整)的朋友,问你1这个人有一个书,每个人都想看,只能从朋友之间传递,然后最后回到了1这个人,问你是否有解,然后有解输出路径收获:哈密尔顿路一:Dirac定理(充分条件) ... 查看详情
sgu294he'scircles(代码片段)
Description有一个长度为N的环,上面写着’X’和’E’,问本质不同的环有多少种。(N不超过200000)。InputTheinputfilecontainsasingleinteger1<=n<=200000.OutputOutputasingleinteger---thenumbercircularstringsoflengthn.SampleInput3SampleOut 查看详情