先上题目:
Accept: 332 Submit: 636
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
In the story of “Alibaba and forty robbers”, Alibaba uses his clever wit to overcome the ferocious enemy, and inherits the huge treasure. There are many treasures which is the rectangular net made by pearls, using silver strand to connect each other. Alibaba would like to cut some number of silver strand to make a pearl necklace. Your question is, given the size of pearls net, can Alibaba cut some of silver strand without wasting a pearl to make a pearl necklace(you can wear it in your neck)?
Input
The first line is a positive number C (C <= 1000), which is the number of test data. The following C lines, each line has two positive integers, M, N, represent the pearls net’s height and width respectively, the two integer are separated by a space. (1 <= M <= 1000, 1 <= N <= 1000).
Output
If we can cut some of silver strand without wasting a pearl to make a pearl necklace, output “Yes”, otherwise output “No”.
Sample Input
Sample Output
Hint
There is a way to cut the net when M=4 and N=6.
题意:给你一个n*m的矩阵,分成n*m个小正方形,问能不能从一个边和边的交点出发,每个交点经过一次,最终回到起点。
找规律,只要有一条边是偶数的时候就可以满足条件,除非另一条边是1,只要有一条边是1的话那就不可以形成回路。
上代码:
1 #include <cstdio> 2 3 using namespace std; 4 5 int main() 6 { 7 int n,a,b,s; 8 //freopen("data.txt","r",stdin); 9 scanf("%d",&n); 10 while(n--){ 11 scanf("%d %d",&a,&b); 12 s=a*b; 13 if(s%2==0 && a!=1 && b!=1) printf("Yes "); 14 else printf("No "); 15 } 16 return 0; 17 }