火眼金睛
来源:互联网 发布:魔兽世界mac air 编辑:程序博客网 时间:2024/04/29 16:30
现在我们需要查出一些作弊的问答社区中的ID,作弊有两种:1.A回答了B的问题,同时B回答了A的问题。那么A和B都是作弊。2.作弊ID用户A和作弊ID用户B同时回答了C的问题,那么C也是作弊。已知每个用户的ID是一串数字,一个问题可能有多个人回答
输入描述:
每组数据第一行为总问题数N(N小于等于200000),第二行开始每行一个问题,第一个数字为提问人ID,第二个数字为回答人数,后面则为所有回答人的ID。(ID均为0-1000000的整数)
输出描述:
第一行为作弊ID数量,第二行开始为从小到大的每行一个作弊ID。
输入例子:
31 1 22 1 13 2 1 2
输出例子:
31 2 3
这道题我参考使用连接图的方式来做,这样做出来的程序看起来比较清楚。
代码如下:
import java.util.*;public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); while(s.hasNext()) { int N = s.nextInt(); int[][] table = new int[N+1][N+1]; for(int i=0; i<N; i++) { int id = s.nextInt(); int nums = s.nextInt(); int[] ids = new int[nums]; for(int j=0; j<nums; j++) { ids[j] = s.nextInt(); table[id][ids[j]] = 1; } } boolean[] isWro = new boolean[N+1]; for(int i=1; i<=N; i++) { for(int j=1; j<=N; j++) { if(j!=i && table[i][j]==1 && table[j][i]==1) { isWro[i] = true; isWro[j] = true; } } } for(int i=1; i<=N; i++) { int count = 0; if(isWro[i]==false) { for(int j=1; j<=N; j++) { if(j!=i && table[i][j]==1 && isWro[j]==true) { count++; if(count==2) { isWro[i] = true; break; } } } } } int num_all = 0; for(int i=1; i<=N; i++) { if(isWro[i]==true) num_all++; } System.out.println(num_all); int t = 0; for(int i=0; i<=N; i++) { if(isWro[i]) { t++; System.out.print(i); if(t != num_all) System.out.print(" "); else System.out.println(); } } } s.close(); }}
0 0
- 火眼金睛
- 火眼金睛
- 火眼金睛
- TASKLIST——火眼金睛
- 照妖镜和火眼金睛
- 华为机试---火眼金睛
- 火眼金睛:continue&break
- 搜狗——火眼金睛
- 18项火眼金睛
- 牛客网---2016---搜狗火眼金睛
- 练就火眼金睛 教你识别翻新笔记本电脑
- 火眼金睛 教你看懂电源内部用料
- HHUOJ 1014 火眼金睛(另类思路题)
- 展示火眼金睛 教你学会内存优劣的识别技巧
- 一目了然电脑配置的火眼金睛是如何练成的
- 擦亮火眼金睛 识别ERP合同陷阱有技巧
- 练就火眼金睛,一眼洞察坑爹P2P平台
- 火眼金睛 | 应用崩溃惯用三大杀招,你中招了么?
- C# 反射(Reflection)
- SpringBoot-log4j
- List vs IEnumerable vs IQueryable vs ICollection vs IDictionary
- 为自己烧钱!!!
- 51nod 1033骨牌覆盖 V2
- 火眼金睛
- 山东省第三届ACM大学生程序设计竞赛 Fruit Ninja I(01背包)
- C# 属性(Property)
- liunx系统下常用命令
- JSON使用JsonProperty Attribute
- JsonConfig
- C# 索引器(Indexer)
- kinect for Unity开发
- 设计公司的高端logo设计