zoukankan      html  css  js  c++  java
  • 1047A_Little C Loves 3 I(构造)

    A. Little C Loves 3 I
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little C loves number «3» very much. He loves all things about it.

    Now he has a positive integer nn. He wants to split nn into 33 positive integers a,b,ca,b,c, such that a+b+c=na+b+c=n and none of the 33 integers is a multiple of 33. Help him to find a solution.

    Input

    A single line containing one integer nn (3n1093≤n≤109) — the integer Little C has.

    Output

    Print 33 positive integers a,b,ca,b,c in a single line, such that a+b+c=na+b+c=n and none of them is a multiple of 33.

    It can be proved that there is at least one solution. If there are multiple solutions, print any of them.

    Examples
    input
    Copy
    3
    output
    Copy
    1 1 1
    input
    Copy
    233
    output
    Copy
    77 77 79
    被样例困惑了很久,看了题解啧啧,其实这题就是构造
    大致题意:给你一个数n,找到三个数a,b,c,使得a+b+c=n,并且a,b,c都不能是3的倍数
    分析:当n%3=0时,n-2一定不是3的倍数,可以构造为a=1,b=1,c=n-2;当n%3!=0时,n-3一定不是3的倍数,那么可以构造为,a=1,b=2,c=n-3.注意这个构造是任意的,只要满足条件即可
     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int main()
     6 {
     7     int n;
     8     while(~scanf("%d",&n))
     9     {
    10         if(n%3==0)
    11             printf("1 1 %d
    ",n-2);
    12         else
    13             printf("1 2 %d
    ",n-3);
    14     }
    15     return 0;
    16 }


  • 相关阅读:
    poj2954
    bzoj1863
    bzoj2002
    bzoj1389
    [POJ3041] Asteroids(最小点覆盖-匈牙利算法)
    [POJ2594] Treasure Exploration(最小路径覆盖-传递闭包 + 匈牙利算法)
    [POJ2446] Chessboard(二分图最大匹配-匈牙利算法)
    [luoguP1266] 速度限制(spfa)
    [luoguP1186] 玛丽卡(spfa)
    [luoguP1027] Car的旅行路线(Floyd)
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/9736335.html
Copyright © 2011-2022 走看看