hdu 5926.Mr. Frog’s Game

http://acm.hdu.edu.cn/showproblem.php?pid=5926

题意:判断给出的这个连连看能不能连上(一次就行)

水,在首行首列或者尾行尾列的需要判断一下自己这一行或者这一列有没有能连上的(四个角的行列都需要判断),然后是所有的都判断一下相邻的能不能连就可以了

啪啪啪打完开心的提交,emmmm居然wa了.....怎么看都没错,又重新看了一遍题的时候突然发现人家要的是只有首字母大写的yes和no.....我全大写了,真是个傻子2333

 1 #include<iostream>
 2 using namespace std;
 3 int s[33][33];
 4         int X,Y;
 5 bool ch(int x,int y)
 6 {
 7     int i,j;
 8     if(x==1||x==X)//首行尾行
 9     {
10         j=1;
11         while(j<=Y)
12         {
13             if(s[x][j]==s[x][y]&&y!=j)return 0;
14             j++;
15         }
16     }
17     if(y==1||y==Y)//首列尾列
18     {
19         i=1;
20         while(i<=Y)
21         {
22             if(s[i][y]==s[x][y]&&i!=x)return 0;
23             i++;
24         }
25     }
26     if(x-1>0&&s[x-1][y]==s[x][y])return 0;//判断上下左右
27     if(y-1>0&&s[x][y-1]==s[x][y])return 0;
28     if(x+1<=X&&s[x+1][y]==s[x][y])return 0;
29     if(y+1<=Y&&s[x][y+1]==s[x][y])return 0;
30     return 1;
31 }
32 int main()
33 {
34     int T,I=1;
35     scanf("%d",&T);
36     while(T--)
37     {
38         bool f=1;//游戏是否可行的标志1为不可行
39         printf("Case #%d: ",I++);
40         scanf("%d %d",&X,&Y);
41         int i,j;
42         i=1;
43         while(i<=X)
44         {
45             j=1;
46             while(j<=Y)
47             {
48                 scanf("%d",&s[i][j]);
49                 j++;
50             }
51             i++;
52         }
53         i=1;
54         while(i<=X&&f)//如果f为0说明游戏可行终止循环
55         {
56             j=1;
57             while(j<=Y&&f)//如果f为0说明游戏可行终止循环
58             {
59                 if(!ch(i,j))f=0;//可行置0
60                 j++;
61             }
62             i++;
63         }
64         if(!f)
65             printf("Yes\n");
66         else
67             printf("No\n");
68     }
69     return 0;
70 }

原文地址:https://www.cnblogs.com/icfir/p/9022455.html

时间: 2024-10-11 18:17:30

hdu 5926.Mr. Frog’s Game的相关文章

HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 312    Accepted Submission(s): 219 Problem Description One day, you, a clever boy, feel bored in your math class, and then fall

HDU 5926 Basic Mr. Frog’s Game 瞎搞

Mr. Frog’s Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1273    Accepted Submission(s): 625 Problem Description One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese). In this

HDU5926 Mr. Frog’s Game

1 /* 2 HDU5926 Mr. Frog's Game 3 http://acm.hdu.edu.cn/showproblem.php?pid=5926 4 杂题水题 5 * 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 using namespace std; 10 const int Nmax=35; 11 int t,n,m; 12 int mapp[Nmax][Nmax]; 13 int dx[]={0,1,-1,

HDU5924 Mr. Frog’s Problem

1 /* 2 HDU5924 Mr. Frog's Problem 3 http://acm.hdu.edu.cn/showproblem.php?pid=5924 4 数论 5 * 6 */ 7 #include <cstdio> 8 int main() 9 { 10 long long a,b; 11 int t; 12 scanf("%d",&t); 13 for(int k=1;k<=t;k++) 14 { 15 scanf("%lld%l

HDU 4004 The Frog&#39;s Games(基本算法-贪心,搜索-二分)

The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The

HDU 4004 The Frog&#39;s Games 二分 贪心

戳这里:HDU 4004 //思路:二分经典入门题...贪心判方案是否可行 1 #include "bits/stdc++.h" 2 using namespace std; 3 int L, n, m; 4 int pos[500010], dis[500010]; 5 6 bool Cant(int Dis_Jump) 7 { 8 int i, Dis_Sum = 0, Count = 0; 9 for(i = 1; i <= n + 1; ++i) { 10 if(dis[

hdu 4004 The Frog&#39;s Games【二分】

The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 3980    Accepted Submission(s): 1931 Problem Description The annual Games in frogs' kingdom started again. The most famous game

HDU 4004 The Frog&#39;s Games 二分

1.题意:一条河长为L,河上有N块石头,一只青蛙可以利用这些石头从河的一端跳到对岸,可以跳不超过M次,求各种跳法中,找到最小化的最大步长.输入第一行依次给出L.N.M,第二行依次给出N块石头距离起点的距离. 2.分析:这类最小化最大值的问题用二分来求解最高效.先预先处理,连同起点,终点,共N+2个点排序,两两相减得到N+1段距离C[i],即跨一步的最小距离.二分维护mid值,上界为河长L,下界为两两距离之中的最大值maxC[i](反证易知),以mid值分割C[i]数组,分割的段数<=M则mid偏

hdu 4004 The Frog&#39;s Games 【二分】

The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) Total Submission(s): 4565    Accepted Submission(s): 2225 Problem Description The annual Games in frogs' kingdom started again. The most famous game