您的位置:首页 > 编程语言 > Go语言

FOJ有奖月赛-2015年11月 Problem F 攻占计划

2015-11-16 18:15 148 查看
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2210

题     意:告诉你一些点和点与点之间所连接的边问他们中入度为0且出度最大的点

思     路:直接暴力用两个数组计算出度与入度并比较
代码如下:#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
typedef __int64 LL;

int ben[1006], vis[1006];

int main()
{
int n, m;
while( scanf ( "%d %d", &n, &m ) != EOF )
{
memset( ben, 0, sizeof( ben ) );
memset( vis, 0, sizeof( vis ) );
for( int i = 0; i < m; i ++ )
{
int x, y;
scanf( "%d %d", &x, &y );
ben[x]++;
vis[y]++;
}
int mx = -1, ans = -1;
for( int i = 0; i < n; i ++ )
{
if( ben[i] > mx && vis[i] == 0 )
{
mx = ben[i];
ans = i;
}
}
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  algorithm