博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 1182. Team Them Up!
阅读量:7239 次
发布时间:2019-06-29

本文共 3052 字,大约阅读时间需要 10 分钟。

1182. Team Them Up!

Time limit: 1.0 second Memory limit: 64 MB
Your task is to divide a number of persons into two teams, in such a way, that:
  • everyone belongs to one of the teams;
  • every team has at least one member;
  • every person in the team knows every other person in his team;
  • teams are as close in their sizes as possible.
This task may have many solutions. You are to find and output any solution, or to report that the solution does not exist.

Input

For simplicity, all persons are assigned a unique integer identifier from 1 to N.
The first line contains a single integer number N (2 ≤ N ≤ 100) - the total number of persons to divide into teams, followed by N lines - one line per person in ascending order of their identifiers. Each line contains the list of distinct numbers A
ij
 (1 ≤ A
ij
 ≤ N, A
ij
 ≠ i) separated by spaces. The list represents identifiers of persons that i
th
 person knows. The list is terminated by 0.

Output

If the solution to the problem does not exist, then write a single message “No solution” (without quotes). Otherwise write a solution on two lines. On the first line write the number of persons in the first team, followed by the identifiers of persons in the first team, placing one space before each identifier. On the second line describe the second team in the same way. You may write teams and identifiers of persons in a team in any order.

Sample

input output
52 3 5 01 4 5 3 01 2 5 01 2 3 04 3 2 1 0
3 1 3 52 2 4
Problem Author: Vladimir Kotov, Roman Elizarov
 
Problem Source: 2001-2002 ACM Northeastern European Regional Programming Contest
*****************************************************************************************************
求补图&&dfs算法&&背包问题f[][],,,染色问题,程序中有解释
*****************************************************************************************************
1 /*本题主要是要求补图  2 和dfs求连通块,每个连通块分成两部分x[][],y[][];  3 然后再用01背包求出最小值并标记  4 最后输出计算结果,此处注意x[i][0],y[i][0]是表示i个连通块中两部分的数量  5 v[i]数组用于标记,点i属于哪个组。  6 */  7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 using namespace std; 14 const int maxn=110; 15 int e[1001][1001]; 16 int v[1001],x[1001][1001],y[1001][1001]; 17 int f[1001][1001]; 18 int n,m,j,i,p; 19 int tmp; 20 int absw(int x) 21 { 22 return (x<0)?(-x):x; 23 } 24 void init() 25 { 26 cin>>n; 27 memset(e,0,sizeof(e)); 28 for(i=0;i
>tmp&&tmp) 31 { 32 e[i][tmp-1]=1; 33 } 34 } 35 for(i=0;i
absw(j-maxn)) 93 ans=j;//最小差值 94 g1=0; 95 for(i=p-1;i>=0;i--)//背包问题从后往前找 96 if(f[i][ans]==0) 97 { 98 g1+=x[i][0]; 99 for(j=1;j<=x[i][0];j++)v[x[i][j]]=1;100 for(j=1;j<=y[i][0];j++)v[y[i][j]]=2;101 ans-=(x[i][0]-y[i][0]);102 }103 else104 {105 g1+=y[i][0];106 for(j=1;j<=x[i][0];j++)107 v[x[i][j]]=2;108 for(j=1;j<=y[i][0];j++)109 v[y[i][j]]=1;110 ans-=(y[i][0]-x[i][0]);111 }112 //输出计算结果113 cout<
<<' ';114 for(i=0;i
View Code

坚持!!!!!

转载于:https://www.cnblogs.com/sdau--codeants/p/3306909.html

你可能感兴趣的文章
源码安装部署redis
查看>>
windows github 下载慢 修改hosts
查看>>
HTML布局规范
查看>>
关于java加法的编写
查看>>
第七周编程总结
查看>>
CocoaPods的安装使用和常见问题
查看>>
计算机科学,大一学生怎样来爱你(文&PPT)
查看>>
老男孩在创业及培训中28条教导学生感悟语录分享!
查看>>
老板不在,你不得不做出越权的决定,咋办?(考试题系列)
查看>>
如何解决SQL Server 2008 R2中“阻止保存要求重新创建表的更改”的问题!
查看>>
cloudstack 4管理器安装备忘
查看>>
sentry日志管理系统安装以及使用教程
查看>>
python-pip : Depends: python-setuptools (>= 0.6c1) 问题
查看>>
iptables外网一端口通过NAT转发内网一服务器端口上
查看>>
新书推荐
查看>>
程序与生活:生活要持续更新
查看>>
网络安全系列之四十九 IIS6.0权限设置
查看>>
VSphere client 虚拟机克隆及网卡报错处理
查看>>
【第一期】如何打造属于自己的网站编辑器——CKEditor与UEditor之争
查看>>
linux下卷组管理
查看>>