Codeforces 1030A In Search of an Easy Problem 尋找一個簡單的問題

難易度 : 800

英文原文如下

When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard.

If at least one of these n people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.

中文翻譯

在準備比賽的時候,Codeforces的統籌人會試著使第一題盡可能的簡單。這一次,統籌人已經準備了一些題目並問了 n 個人的意見。每一個人都會回答這個問題是簡單還是困難。

如果 n 個人中有至少有一個人認為題目是困難的,統籌人會改變那個問題。針對給予的答覆,確認問題是不是足夠簡單。

輸入

The first line contains a single integer n (1n100) — the number of people who were asked to give their opinions.

The second line contains n integers, each integer is either 0 or 1. If i-th integer is 0, then i-th person thinks that the problem is easy; if it is 1, then i-th person thinks that the problem is hard.

第一行包含了一個整數 n (1n100) — 被詢問意見的人數。

第二行包含了 n 個整數,每一個整數都是 0 或是 1。如果第 i 位的整數是0,則代表第 i 位的人認為題目是簡單的,要是1,則認為題目是困難的。

輸出

Print one word: “EASY” if the problem is easy according to all responses, or “HARD” if there is at least one person who thinks the problem is hard.

You may print every letter in any register: “EASY”, “easy”, “EaSY” and “eAsY” all will be processed correctly.

印出一個單字,要是所有回答都認為是簡單 : “EASY”,或是至少有一個人認為題目是困難的 : “HARD”。

範例

輸入3
0 0 1
輸出HARD
輸入1
0
輸出EASY

解題思路

跑一個簡單的迴圈,並在碰上 1 的時候就可以break掉了,節省點時間。

C#解決方案

方案1

string input = Console.ReadLine(); //unused
string[]arr = Console.ReadLine().Split(' '); //split by space
bool res = false;


foreach(var item in arr){
    if(item=="1"){
        res = true;
        break;
    }
}

Console.WriteLine(res?"HARD":"EASY");

第一行輸入是用不到的,因為我們會直接對所有人的回答去做迴圈判斷。

Java解決方案

方案1

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        String[]arr = scanner.nextLine().split(" "); //split by space
        Boolean res = false;
        
        for(String item : arr){
            if(item.equals("1")){
                res = true;
                break;
            }
        }
        
        System.out.println(res?"HARD":"EASY");
    }
}


結論

🧡如果文章有幫上你的忙,那是我的榮幸

🧡收藏文章或幫我點個廣告,那都是對我的支持

✅如有任何疑問,歡迎透過留言或messenger讓我知道 !

題目連結 : Problem – 1030A – Codeforces

一些其他的Codeforces文章

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *