2014 UESTC Training for Graph Theory F
来源:互联网 发布:嵌入式系统编程 扫描版 编辑:程序博客网 时间:2024/05/22 00:31
HAVEL定理的应用
利用优先队列模拟该过程
取出序列中最大值dmax,若dmax大于n-1,无解退出。否则取出剩下n-1个元素中前dmax大的dmax个元素,把这些元素依次减1后放回序列中,dmax舍弃,n=n-1
利用优先队列模拟该过程
取出序列中最大值dmax,若dmax大于n-1,无解退出。否则取出剩下n-1个元素中前dmax大的dmax个元素,把这些元素依次减1后放回序列中,dmax舍弃,n=n-1
如果出现负数那么则无解
#include <map>#include <set>#include <list>#include <cmath>#include<cctype>#include <ctime>#include <deque>#include <stack>#include <queue>#include <cstdio>#include <string>#include <vector>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define PI 3.1415926535897932626using namespace std;int gcd(int a, int b){return a % b == 0 ? b : gcd(b, a % b);}#define MAXN 100005int sum;int Count;int N;int src[MAXN];struct node{ int data; bool operator < (const node &a) { return data>a.data; }};priority_queue<int>q;void slove(){ sum=0; int tmp=0; bool flag=false; scanf("%d",&N); while (!q.empty()) q.pop(); for (int i=0;i<N;i++) { scanf("%d",&tmp); sum+=tmp; q.push(tmp); } //for (int i=0;i<N;i++) printf("%d ",src[i]);putchar('\n'); if (sum%2!=0) {printf("NO\n");return;} while (!q.empty()) { int cas=0; int tmp=q.top();q.pop(); if (tmp>=N) {flag=true;break;} for (int i=1;i<=tmp;i++) { if (q.empty()) break; src[cas]=q.top();q.pop(); src[cas]--; if (src[cas]<0) {flag=true;break;} cas++; } if (flag) break; for (int i=0;i<cas;i++) q.push(src[i]); N--; } if (!flag)printf("YES\n"); else printf("NO\n");}int main(){ int T; scanf("%d",&T); while (T--) slove(); return 0;}
0 0
- 2014 UESTC Training for Graph Theory F
- 2014 UESTC Training for Graph Theory Problem F 握手
- 2014 UESTC Training for Graph Theory B
- 2014 UESTC Training for Graph Theory C
- 2014 UESTC Training for Graph Theory G
- 2014 UESTC Training for Graph Theory H
- 2014 UESTC Training for Graph Theory I
- 2014 UESTC Training for Graph Theory J
- 2014 UESTC Training for Graph Theory K
- 2014 UESTC Training for Graph Theory L
- UESTC Training for Graph Theory——F、Instantaneous Transference
- 2014 UESTC Training for Graph Theory Problem K WHITE ALBUM
- 2016 UESTC Training for Graph Theory
- 2017 UESTC Training for Graph Theory
- 2017 UESTC Training for Graph Theory 题解
- UESTC Training for Graph Theory——A、Railway
- UESTC Training for Graph Theory——B、Asteroids
- UESTC Training for Graph Theory——c、Catenyms
- 期末上机赛解题报告及标程
- 实现真·转发效果的Twitter 移动端
- 2014 UESTC Training for Graph Theory B
- 2014 UESTC Training for Graph Theory C
- 脱离jsonp,如何跨域读取、提交数据
- 2014 UESTC Training for Graph Theory F
- win8系统下Ctrl+Alt+方向键的困扰
- 2014 UESTC Training for Graph Theory G
- DB2 runstats、reorgchk、reorg 命令
- leetcode:Single Number II
- 2014 UESTC Training for Graph Theory H
- 2014 UESTC Training for Graph Theory I
- activex与前台JS交互
- 2014 UESTC Training for Graph Theory J