gpt4 book ai didi

c - 打印纸将邮票填满方形纸,没有任何重叠

转载 作者:行者123 更新时间:2023-11-30 19:42:37 25 4
gpt4 key购买 nike

我为在线类(class)编写了以下 C 程序。它似乎正在工作并给出相关输出,但是当我提交程序时,我被告知它给出了“错误答案”。

#include <stdio.h> 

int main() {

long int n;

scanf(“%ld”,&n);

if(n>1) {
if(n%2||n%3)
printf(“YES”);
else
printf(“NO”);
}
else if(n==1) {
printf(“NO”);
}

return 0;
}

这就是程序应该做的事情:

Ted (the popular talking bear) has been given a job at the printing firm. Looking at his previous employment record, the firm is watching very strictly on his work product. Recently, he has been assigned a task to print on a square sheet of dimension NxN. You may think of the sheet containing N2 cells of dimension 1x1 each. Since, Ted is a lazy bear, he somehow steals two stamps, a horizontal printing stamp which covers a 1*2 block and a vertical printing stamp which covers a 3*1 block. He may use these two stamps in any order and as many times as he wants. But the sheets are old, if the sheet is stamped twice at any cell, it will tear off. Now, there is a shipment of sheets coming with varying sizes. But he observes that in some of the cases it is not possible to completely fill the square sheet with no overlapping stamps. So, he asks for your help in deciding whether it is possible to fill the square sheet with the stamps without any overlapping.

Input consists of a single integer N denoting the side of the square sheet.

Output a single line containing “YES” (without quotes) if it is possible to fill the square sheet without overlapping the stamps and “NO” (without quotes) otherwise.

Constraints:

1 ≤ N ≤ 106

示例输入:

2

示例输出:

YES

如何修复我的程序?

最佳答案

我不知道你的算法是否正确,但我认为而不是:

if(n%2||n%3)

你想写:

if(n%2 == 0 || n%3 == 0)

这里n%2 == 0表示n可以被2整除。

关于c - 打印纸将邮票填满方形纸,没有任何重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31412097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com