UVa 10763 (STL) Foreign Exchange
看到大神说location的值不会超过1000,所以这就简单很多了,用一个deg数组记录下来每个点的度,出度-1,入读+1这样。
最后判断每个点的度是否为0即可。
至于为什么会这样,据说是套数据套出来的,比如在代码里加一句if(a >= 1000) for(;;),get新技能!
如果按正常来做的话,我能想到的就是遍历map了。
#include <cstdio>
#include <cstring> const int maxn = ;
int deg[maxn]; int main()
{
//freopen("in.txt", "r", stdin); int n;
while(scanf("%d", &n) == && n)
{
memset(deg, , sizeof(deg));
int a, b;
for(int i = ; i < n; i++)
{
scanf("%d%d", &a, &b);
deg[a]++; deg[b]--;
}
bool ok = true;
for(int i = ; i < maxn; i++) if(deg[i]) ok = false;
printf("%s\n", ok ? "YES" : "NO");
} return ;
}
代码君
UVa 10763 (STL) Foreign Exchange的更多相关文章
- UVA 10763 Foreign Exchange 出国交换 pair+map
题意:给出很多对数字,看看每一对(a,b)能不能找到对应的(b,a). 放在贪心这其实有点像检索. 用stl做,map+pair. 记录每一对出现的次数,然后遍历看看对应的那一对出现的次数有没有和自己 ...
- uva 10763 Foreign Exchange(排序比较)
题目连接:10763 Foreign Exchange 题目大意:给出交换学生的原先国家和所去的国家,交换成功的条件是如果A国给B国一个学生,对应的B国也必须给A国一个学生,否则就是交换失败. 解题思 ...
- uva:10763 - Foreign Exchange(排序)
题目:10763 - Foreign Exchange 题目大意:给出每一个同学想要的交换坐标 a, b 代表这位同学在位置a希望能和b位置的同学交换.要求每一位同学都能找到和他交换的交换生. 解题思 ...
- uva 10763 Foreign Exchange <"map" ,vector>
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enthu ...
- UVA Foreign Exchange
Foreign Exchange Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Your non ...
- Foreign Exchange
10763 Foreign ExchangeYour non-profit organization (iCORE - international Confederation of Revolver ...
- Foreign Exchange(交换生换位置)
Foreign Exchange Your non-profit organization (iCORE - international Confederation of Revolver Enth ...
- [刷题]算法竞赛入门经典(第2版) 5-4/UVa10763 - Foreign Exchange
题意:有若干交换生.若干学校,有人希望从A校到B校,有的想从B到C.C到A等等等等.如果有人想从A到B也刚好有人想从B到A,那么可以交换(不允许一对多.多对一).看作后如果有人找不到人交换,那么整个交 ...
- UVA 10763 Foreign Exchange
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description Your non- ...
随机推荐
- Long型070000L前面0去掉比较大小,token,mysql innodb,properties,switch匹配空字符串对象
public class TestJava { //定义获取资源文件 private static final ResourceBundle bundle = initBundle(); privat ...
- POJ 1661 Help Jimmy (dijkstra,最短路)
刚在百度搜索了一下这道题的题解, 因为看到有别人用动态规划做的,所以想参考一下. 结果顺带发现了有那么几个网站,上面的文章竟然和我这篇一模一样(除了一些明显的错别字外),我去,作者还是同一个人Admi ...
- Xamarin for Mac 2.0.2.35 稳定版 破解补丁 Preview 2
注意:该破解补丁未经过广泛测试 前提概要 1.该补丁,仅涉及以下产品,所有版权归 Xamarin 所有,仅供学习练手: ① Xamarin.iOS 8.10.2.37 Xamarin.iOS 8.10 ...
- 初学Ajax(一)
以下文字根据李炎恢——jQuery教程整理而成. Ajax全称为:“Asynchronous JavaScript and XML”(异步JavaScript和XML),它并不是JavaScript的 ...
- iOS多线程 GCD
iOS多线程 GCD Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. dispatch queue分成以下三种: 1)运行在主线程的Main que ...
- interviewbit :Min Steps in Infinite GridBookmark Suggest Edit
You are in an infinite 2D grid where you can move in any of the 8 directions : (x,y) to (x+1, y), (x ...
- ios开发--animation flash动画
/** * showAnimationFlash */ + (void)showAnimationFlashWithView:(UIView *)animationView durati ...
- 一个国外网盘pCloud——支持离线下载
给大家分享一个国外网盘<支持离线下载> https://my.pcloud.com/#page=register&invite=HiegZ8aBrt7
- QT程序探测所需DLL,静态连接和打包
1. 如果没有使用静态编译的QT库的话,那么无论VS还是MinGW编译出来的exe程序都要带上一堆DLL,而且必须是准确版本的DLL,对于VS好像还有一个Microsoft.VC90.CRT.mani ...
- Java笔记——面向接口编程(DAO模式)
1.DAO模式 DAO(Data Access Object)模式就是写一个类,把访问数据库的代码封装起来.DAO在数据库与业务逻辑(Service)之间. l 实体域,即操作的对象,例如 ...