poj 2458 Rigging the Bovine Election
来源:互联网 发布:阿里云服务器搭建云免 编辑:程序博客网 时间:2024/05/21 11:29
已醉。。。
在联通性的判断上搞错了一下,在只能横竖走的情况下,只要最后的模块联通就行了,并不需要在7层循环每层都联通
/*ID: daniel.20LANG: JAVATASK: tour */import java.util.*;import java.io.*;class pb1{ int arr[]; void solver() throws IOException{ //Scanner scan = new Scanner(System.in); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); arr = new int[25]; for(int i=0;i<5;i++){ String tmp = reader.readLine(); for(int j=0;j<5;j++){ if(tmp.charAt(j)=='H') arr[i*5+j]=1; else arr[i*5+j]=0; } } int count = 0; for(int a1=0;a1<25;a1++){ int b1=arr[a1]; for(int a2=a1+1;a2<25;a2++){ int b2=b1+arr[a2]; for(int a3=a2+1;a3<25;a3++){ int b3=b2+arr[a3]; for(int a4=a3+1;a4<25;a4++){ int b4=b3+arr[a4]; if(b4>=4) continue; for(int a5=a4+1;a5<25;a5++){ int b5=b4+arr[a5]; if(b5>=4) continue; for(int a6=a5+1;a6<25;a6++){ int b6=b5+arr[a6]; if(b6>=4) continue; for(int a7=a6+1;a7<25;a7++){ int b7=b6+arr[a7]; if(b7>=4) continue; //System.out.println(a1+" "+a2+" "+a3+" "+a4+" "+a5+" "+a6+" "+a7); if(is_connected(a1,a2,a3,a4,a5,a6,a7)) count++; } } } } } } } System.out.println(count); } boolean is_connected(int a, int b, int c, int d, int e, int f, int g){ boolean is_target[] = new boolean[25]; is_target[a]=is_target[b]=is_target[c]=is_target[d]=is_target[e]=is_target[f]=is_target[g]=true; boolean vis[] = new boolean[25]; int level[] = new int[25]; int count = 0; int dir[][] = {{-1,0},{1,0},{0,-1},{0,1}}; LinkedList<Integer> q = new LinkedList<Integer>(); q.add(a);vis[a]=true; while(!q.isEmpty()){ int tmp = q.poll(); if(is_target[tmp]) count++; if(count==7) return true; int x=tmp/5; int y=tmp%5; for(int i=0;i<4;i++){ int nx = x+dir[i][0]; int ny = y+dir[i][1]; if(nx>=0&&nx<5&&ny>=0&&ny<5&&!vis[nx*5+ny]&&level[nx*5+ny]<=6&&is_target[nx*5+ny]){ vis[nx*5+ny]=true; level[nx*5+ny]=level[tmp]+1; q.push(nx*5+ny); } } } return false; }}public class tour { public static void main(String[] args) throws Exception { pb1 p = new pb1(); p.solver(); }}
0 0
- poj 2458 Rigging the Bovine Election
- POJ 2458 Rigging the Bovine Election
- bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
- bzoj 1675: [Usaco2005 Feb]Rigging the Bovine Election 竞选划区(暴力)
- poj 3407 Bovine Birthday
- poj 3047 Bovine Birthday
- POJ 3175 Finding Bovine Roots
- POJ - 2183 Bovine Math Geniuses
- Poj 2183 Bovine Math Geniuses
- poj 2183 Bovine Math Geniuses
- POJ 2183 Bovine Math Geniuses
- POJ 3175 Finding Bovine Roots
- POJ 3175 Finding Bovine Roots
- POJ 3175 Finding Bovine Roots
- POJ 3175 Finding Bovine Roots
- POJ 3047 Bovine Birthday 笔记
- poj 2643 Election
- poj 3664 Election Time
- 关于组合游戏
- POJ 题目3041 Asteroids(二分图)
- .Net单元测试(二)——XML数据载体的优势与实际应用
- 大数据技术趋势以及未来方向
- 日经社説 20150224 訪日客の多様化に応じた通訳ガイド育め
- poj 2458 Rigging the Bovine Election
- 超低功耗物联网
- 社説 20150224 与那国住民投票 国防を地方政争の具にするな
- 社説 20150224 西川農相辞任 農業改革の体制再建が急務だ
- WCF简介
- pat2-09
- 【POJ3810】Magina
- NYOJ-682 小媛在努力 (郑大第六届校赛 模拟)
- 对ThreadLocal的初步理解