Codeforces Round #278 (Div. 2) b

/**
 *
 * @brief Codeforces Round #278 (Div. 2) b
 * @file b.c
 * @author mianma
 * @created 2014/11/24 17:52
 * @edited  2014/11/18 17:52
 * @type brute
 * 
 * @note 
 *          declare k >= 0;
 *              then 
 *                  x1 = k
 *                  x2 + x3 = 4k;
 *                  x4 = 3k
 *                  x1 <= x2 <= x3 <= x4
 *
 */
#include <cstdio>
#include <vector>
using namespace std;
#define MAXN 2000
#define max(a, b)  ((a) > (b) ? (a) : (b))
#define min(a, b)  ((a) > (b) ? (b) : (a)) 
#define abs(a)     ((a) >  0  ? (a) : (0 - (a)))
int tmp;
int n;
int table[MAXN + 50];
int anstable[MAXN + 50];
int usetable[MAXN + 50];
int main()
{
#ifdef DEBUG
    freopen("./in",  "r", stdin);
    freopen("./out", "w", stdout);
#endif
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &tmp);
            table[tmp]++;
    }
    if(!n){
        printf("YES\n");
        printf("1\n1\n3\n3\n");
        return 0;
    }
    int a, b, c, d;
    for(a = 0; a <= 500; a++)
        for( d = 3*a, b = 0; b <= 4*a; b++){
                c = a + d - b;
        if(a <= b && b <= c && c <=d)
                 ;
        else
              continue;
                anstable[a]++;
                anstable[b]++;
                anstable[c]++;
                anstable[d]++;
                int cnt;
                int cost = 0;
                int tot  = 0;
                if(!usetable[a] && anstable[a] >= table[a]){
                      anstable[a] -= table[a];
                      cost        += table[a];
                      usetable[a] = 1;
                 }
                if(!usetable[b] && anstable[b] >= table[b]){
                     anstable[b] -= table[b];
                     cost      += table[b];
                     usetable[b] = 1;
                }

                if(!usetable[c] && anstable[c] >= table[c]){
                     anstable[c] -= table[c];
                     cost      += table[c];
                     usetable[c] = 1;
                }
                if(!usetable[d] && anstable[d] >= table[d]){
                     anstable[d] -= table[d];
                     cost      += table[d];
                     usetable[d] = 1;
                 }
                  
                if(cost == n){
#ifdef DEBUG
      printf("a = %d, b = %d, c = %d, d = %d\n", a, b, c, d);
#endif
      //return 0;
                    printf("YES\n");
                    while(anstable[a]-- > 0)
                        printf("%d\n", a);
                    while(anstable[b]-- > 0)
                        printf("%d\n", b);
                    
                    while(anstable[c]-- > 0)
                        printf("%d\n", c);
                    while(anstable[d]-- > 0)
                        printf("%d\n", d);
                    
                    return 0;
                }else{
                    anstable[a] = 0;
                    anstable[b] = 0;
                    anstable[c] = 0;
                    anstable[d] = 0;
                    usetable[a] = 0;
                    usetable[b] = 0;
                    usetable[c] = 0;
                    usetable[d] = 0;
                }
            }
            printf("NO\n");
    return 0;
}
时间: 2024-10-17 19:09:51

Codeforces Round #278 (Div. 2) b的相关文章

Codeforces Round #278 (Div. 2) d

/**  * @brief Codeforces Round #278 (Div. 2) d  * @file d.c  * @author 面码  * @created 2014/11/26 10:07  * @edited  2014/11/26 10:07  * @type dp   * @note  *      自己的TL了,看了别人代码写的  *      该代码主要是在dp的基础上使用stl来提速  *      dp需辅助提速,但内存又不能爆掉是该题目的卡点 = =  */ #i

Codeforces Round #278 (Div. 2) c

/**  * @brief Codeforces Round #278 (Div. 2) c  * @file c.c  * @author 面码  * @created 2014/11/25 14:15  * @edited  2014/11/25 14:15  * @type brute  *  */ #include <stdio.h> #define max(a, b)  ((a) > (b) ? (a) : (b)) #define min(a, b)  ((a) > (

Codeforces Round #278 (Div. 1)

A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's H

CodeForces Round #278 (Div.2) (待续)

A 这么简单的题直接贴代码好了. 1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 5 bool islucky(int a) 6 { 7 a = abs(a); 8 while(a) 9 { 10 if(a % 10 == 8) return true; 11 a /= 10; 12 } 13 return false; 14 } 15 16 int main(void) 17 { 18 int a,

Codeforces Round #278 (Div. 2)

A直接暴力好了. 1 #include<bits/stdc++.h> 2 typedef long long ll; 3 using namespace std; 4 5 int pan(ll x) 6 { 7 while (x) 8 { 9 if (x%10==8) return 1; 10 x/=10; 11 } 12 return 0; 13 } 14 15 int main() 16 { 17 ll n; 18 cin>>n; 19 for (int i=1;i<=1

Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]

哎,最近弱爆了,,,不过这题还是不错滴~~ 要考虑完整各种情况 8795058                 2014-11-22 06:52:58     njczy2010     B - Candy Boxes             GNU C++     Accepted 31 ms 4 KB 8795016                 2014-11-22 06:48:15     njczy2010     B - Candy Boxes             GNU C+

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿