Codechef巨大的输入测试解决方案

时间:2015-11-12 06:28:02

标签: c algorithm

我在codechef https://www.codechef.com/problems/INTEST

上解决了这个问题

我正在使用以下代码,它在我的系统上给出了正确的答案,但在我提交时给出了错误的答案。那是为什么?

#include <stdio.h>

int main(void) 
{
    unsigned int n, k, ti, dv;
    scanf("%d %d", &n, &k);
    int i = 0;
    while (i < n)
    {
        scanf("%d", &ti);
        if ((ti % k) == 0)
            dv++;
        i++;
    }
    printf("%d", dv);

    return 0;
}

我尝试了问题页面上给出的输入并得到了正确的答案

2 个答案:

答案 0 :(得分:1)

Python3解决方案-

n,k = list(map(int,input().split()))
count = 0
for _ in range(n):
    if (int(input()) % 3 == 0):
    count+=1
print(count)

答案 1 :(得分:1)

这是我针对该问题的 Python3 解决方案:

#[derive(Copy, Clone, Eq, PartialEq)]
struct Player;

struct Position {
    row: usize,
    col: usize,
}

#[derive(Eq, PartialEq)]
enum Cell {
    Filled(Player),
}

const SIZE: usize = 10;

struct Board {
    // state: GameState,
    cells: [[Cell; SIZE]; SIZE],
}

impl Board {
    fn mark(&mut self, pos: &Position, player: Player) {
        self.cells[pos.row][pos.col] = Cell::Filled(player);
        if all_in_line(player, |i: usize| &self.cells[pos.row][i])
            || all_in_line(player, |i: usize| &self.cells[i][pos.col])
        {
            // self.state = GameState::Winner(player);
        }
    }
}

fn all_in_line<'a, F>(player: Player, cell_access: F) -> bool
where
    F: Fn(usize) -> &'a Cell,
{
    (0..SIZE)
        .map(cell_access)
        .all(|c| *c == Cell::Filled(player))
}