列表

详情


NC207581. SumoandCoins

描述

There are n coins on Sumo's table, each coin has two sides, of the coins face up, and of the coins face down. Sumo wants to make these coins have the same side.

Each time he can flip any n-1 of these coins, he can do this operation any number of times(possibly zero).

Please tell him if he can make these coins have the same side.

输入描述

The first line of the input is a single integer , T test cases follow.

Each test case has three integers , a, b(a+b=n).

输出描述

If all the coins can face up or down, output "ALL"(without quotes);

If all the coins can only face up, output "UP"(without quotes);

If all the coins can only face down, output "DOWN"(without quotes);

If all the coins cannot face the same side, output "NULL"(without quotes).

示例1

输入:

1
2 1 1

输出:

ALL

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 36ms, 内存消耗: 608K, 提交时间: 2020-06-06 15:43:46

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int t,n,a,b;	cin>>t;
	while(t--){
		cin>>n>>a>>b;
		if(n%2==0)	cout<<"ALL"<<endl;
		else{
			if(a%2==1)	cout<<"UP"<<endl;
			else	cout<<"DOWN"<<endl;
		} 
	}
}

C(clang 3.9) 解法, 执行用时: 6ms, 内存消耗: 376K, 提交时间: 2020-10-10 21:36:57

#include<stdio.h>
int main() {
	int t,n,a,b;
	scanf("%d",&t);
	while(t--) {
		scanf("%d%d%d",&n,&a,&b);
		if(a % 2 == b % 2)
			printf("ALL\n");
		else{
			if(a % 2 == 1)
				printf("UP\n");
			else
				printf("DOWN\n");
		}
	}
} 

C++11(clang++ 3.9) 解法, 执行用时: 7ms, 内存消耗: 488K, 提交时间: 2020-06-06 16:39:15

#include<stdio.h>
int main()
{
	int t,n,a,b;
	scanf("%d",&t);
	while (t--) {
		scanf("%d%d%d",&n,&a,&b);
		if (n%2==0) printf("ALL\n");
		else if (a&1) printf("UP\n");
        else printf("DOWN\n");
	}
	return 0;
}

Python3(3.9) 解法, 执行用时: 77ms, 内存消耗: 2936K, 提交时间: 2021-03-23 16:18:50

for _ in range(int(input())):
    n,a,b=map(int,input().split())
    if n%2==0:
        print('ALL')
    elif a%2==1:
        print('UP')
    else:
        print('DOWN')

上一题