uva-10720-贪心
题意:对于一个简单图(不存在平行边和自旋边),输入所有的点的度,问,能不能变成一个简单图.
解题思路:
可图化定理.https://blog.csdn.net/shuangde800/article/details/7857246
对所有点的度从大到小排序,每次都选取一个度最大的点(度为n),往后的n个点度数每个都减一,如果,发现出现负数,或者不够减,那就不能变成简单图.
WA了很多次,主要错在以下俩个原因,刚开始从小的开始删除.考虑下面这组输入,
4 1 1 2 2,如果从小的开始删,第一次删除后变成 0 0 2 2 ,这个一个错误的图.
第二次只排了一次.
第一次排序后 d1 >= d2 >= d3 >= ......dn,但是在删除一次后,不保证序列还是递减.
#include "pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset> namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap;
using std::stack;
using std::bitset; constexpr int N = ; int a[N];
int n;
bool check()
{
for (int i = ;i < n - ;i++)
{
sort(a + i, a + n, greater<int>());
if (i + a[i] >= n) return false;
for (int j = i + ;j <= i + a[i];++j)
{
--a[j];
if (a[j] < )return false;
}
}
if (a[n - ] != )
return false;
return true;
} void solve()
{
while (cin >> n && n)
{
memset(a, , sizeof(a));
int ok = ;
for (int i = ;i < n;i++)
{
cin >> a[i];
if (a[i] >= n)
{
ok = ;
}
} if (ok == && check())
{
cout << "Possible" << endl;
}
else
{
cout << "Not possible" << endl;
}
} } }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return ;
}
uva-10720-贪心的更多相关文章
- UVA 10720 Graph Construction 贪心+优先队列
题目链接: 题目 Graph Construction Time limit: 3.000 seconds 问题描述 Graph is a collection of edges E and vert ...
- 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...
- UVA 11389(贪心问题)
UVA 11389 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description II ...
- uva 10154 贪心+dp
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVa 11389 (贪心) The Bus Driver Problem
题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...
- UVa 1467 (贪心+暴力) Installations
题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...
- Party Games UVA - 1610 贪心
题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...
- UVa 10720 - Graph Construction(Havel-Hakimi定理)
题目链接: 传送门 Graph Construction Time Limit: 3000MS Memory Limit: 65536K Description Graph is a coll ...
- UVa 1149 (贪心) Bin Packing
首先对物品按重量从小到大排序排序. 因为每个背包最多装两个物品,所以直觉上是最轻的和最重的放一起最节省空间. 考虑最轻的物品i和最重的物品j,如果ij可以放在一个包里那就放在一起. 否则的话,j只能自 ...
- UVA 10037 贪心算法
题目链接:http://acm.hust.edu.cn/vjudge/contest/122829#problem/A 题目大意:N个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...
随机推荐
- 一:elasticsearch常用操作总结
索引 搜索 mapping 分词器 1.创建索引 http://192.168.65.131:9200/smartom_index 2.查看索引: http://192.168.65.131:9200 ...
- Delegate event 委托事件---两个From窗体使用委托事件
窗体如下: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void b ...
- Selenium2+python自动化38-显式等待(WebDriverWait)
From: https://www.cnblogs.com/yoyoketang/p/6517477.html 前言: 在脚本中加入太多的sleep后会影响脚本的执行速度,虽然implicitly_w ...
- 【spring boot】映射properties文件属性--到Java对象
描述 将*.properties中的内容映射到java对象中: 主要步骤 添加 @Component 注解: 使用 @PropertySource 注解指定配置文件位置: 使用 @Configurat ...
- Unity3d- 资源
Data与Resources文件夹一般只读文件放到Resources目录Data用于新建的文件或者要修改的文件============================================= ...
- [ZZ]Appium 文档翻译
http://testerhome.com/topics/150 Appium 是一个开源的,适用于原生或混合移动应用应用( hybrid mobile apps )的自动化测试平台. Appium ...
- bzoj4814: [Cqoi2017]小Q的草稿
Description 小Q是个程序员.众所周知,程序员在写程序的时候经常需要草稿纸.小Q现在需要一张草稿纸用来画图,但是桌上 只有一张草稿纸,而且是一张被用过很多次的草稿纸.草稿纸可以看作一个二维平 ...
- OpenSSH多路复用Multiplexing配置
设置 Session Multiplexing 在客户端节点如下配置/etc/ssh/ssh_config 或~/.ssh/config 就可以直接开启 Session Multiplexing 功能 ...
- file /usr/lib64/mysql/plugin/dialog.so from install of Percona-Server-server-56-5.6.24-rel72.2.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.60-1.el7_5.x86_64
!!!点下面!!! https://www.cnblogs.com/chuijingjing/p/10005922.html
- JSON 使用
ylbtech-JSON: JSON 使用 1. 把 JSON 文本转换为 JavaScript 对象返回顶部 JSON 最常见的用法之一,是从 web 服务器上读取 JSON 数据(作为文件或作为 ...