HDU 5813(贪心,构造,多校)
来源:互联网 发布:淘宝玩具店铺简介 编辑:程序博客网 时间:2024/06/11 07:37
题目链接:HDU 5813
题意:给一个有向图,
解题思路:官方给出的题解说的很清楚,刚开始还以为是跟如论有关的东西,还是自己太天真了。直接贪心就好,好水的一道题,比赛时觉得跟图有关被吓到了。赛后才知道原来这么简单。
AC代码:
#include <iostream>#include <stdio.h>#include <cmath>#include <cstring>#include <algorithm>#include <queue>#include <map>using namespace std;#define ll long longstruct Point{ int num; int id;}p[1010];bool cmp(Point a,Point b){ return a.num<b.num;}int main(){ int T,n; scanf("%d",&T); int cas=1; while(T--) { int ans=0; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&p[i].num); p[i].id=i; ans+=p[i].num; } sort(p+1,p+n+1,cmp); int flag=1; for(int i=1;i<=n;i++) { if(p[i].num>i-1) { flag=0; } } if(flag==0) printf("Case #%d: No\n",cas++); else { printf("Case #%d: Yes\n%d\n",cas++,ans); for(int i=2;i<=n;i++) { for(int j=1;j<=p[i].num;j++) printf("%d %d\n",p[i].id,p[j].id); } } } return 0;}
0 0
- HDU 5813(贪心,构造,多校)
- hdu 5813 Elegant Construction 贪心构造
- HDU-#5014 Number Sequence(贪心+构造)
- hdu 5353 Average(贪心+构造)
- HDU 5385 The path(贪心+构造)
- HDU 5881 Tea(贪心构造)
- hdu 5573贪心构造
- hdu 4982 贪心构造序列
- HDU 5301(Buildings-贪心构造)
- hdu 5813 Elegant Construction 贪心(多校)
- 贪心,模拟,构造(HDU 5414,CRB and String)
- hdu 5113 Black and White(贪心构造)
- hdu 5385 The path 贪心?构造
- Hdu-5573 Binary Tree(贪心构造)
- Codeforces738E-Subordinates(贪心+构造)
- HDU 6090 Rikka with Graph (贪心+构造, 2017 Multi-Univ Training Contest 5)
- HDU-5813-Elegant Construction【多校2016】【贪心】
- hdu 5813 Elegant Construction(贪心)
- Facial Landmark Detection
- codeblocks 多线程编程时出现:对pthread_create未定义的引用,解决方法
- $,ajxa动态获取数据表格显示
- 安卓中关于侧滑菜单的简单应用
- POJ 1141 Brackets Sequence(区间dp + dfs)
- HDU 5813(贪心,构造,多校)
- javaMail邮件发送功能(多收件人,多抄送人,多密送人,多附件)
- Java 读写xml文件代码示例
- KUP-11010: unable to open at least one dump file for fetch
- 解决PHP mail发送UTF-8中文邮件乱码
- x264+mp4v2编码YUV420为mp4
- python编程(4):IO
- POJ 1007 DNA Sorting
- Scala学习第二弹 下载和安装