Educational Codeforces Round 96 (Rated for Div. 2) 解题报告

CF1430A Number of Apartments

Educational Codeforces Round 96 第一题,签到。

题目链接

题意翻译

  • 数据组数 \( t \);
  • 求满足 \( a , b , c \in \mathbb { N } \) 且满足 \( 3 a + 5 b + 7 c = n \) 的三元组 \( \left( a , b , c \right) \) 的任意一组解,无解输出 \( – 1 \);
  • 数据范围:\( 1 \leq t \leq 10 ^ 3 \),\( 1 \leq n \leq 10 ^ 3 \)。

题解

不难发现,\( n = 1 , 2 , 4 \) 时无解,其他情况均有解。

#include <bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++)
static char buf[100000], *p1 = buf, *p2 = buf;
inline int read(void)
{
    reg char ch = getchar();
    reg int res = 0;
    while (ch < '0' || '9' < ch)
        ch = getchar();
    while ('0' <= ch && ch <= '9')
        res = 10 * res + ch - '0', ch = getchar();
    return res;
}

int n;

int main(void)
{
    reg int t = read(); //读入数据组数
    while (t--)
    {
        n = read(); //读入 n
        if (n == 1 || n == 2 || n == 4)
            puts("-1");      //无解
        else if (n % 3 == 0) //mod 3 -> 0
            printf("%d 0 0\n", n / 3);
        else if (n % 3 == 1) //mod 3 -> 1
            printf("%d 0 1\n", n / 3 - 2);
        else //mod 3 -> 2
            printf("%d 1 0\n", n / 3 - 1);
    }
    return 0;
}
Pages: 1 2 3 4 5 6 7 8 9