zoukankan      html  css  js  c++  java
  • codeforces 839 B Game of the Rows

    题目链接:http://codeforces.com/contest/839/problem/B

    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    const int maxn = 100 + 5;
    
    int n, k;
    int a[maxn];
    
    void display(int n){
    	for (int i = 0; i < n; ++i){
    		printf("(%d)%d ", i + 1, a[i]);
    	}
    	printf("
    ");
    }
    
    int main(){
    	scanf("%d%d", &n, &k);
    	for (int i = 0; i < k; ++i){
    		scanf("%d", a + i);
    	}
    	int four = n, two = 2 * n, one;
    	int t;
    	//先往3,4,5,6安排士兵
    	for (int i = 0; i < k; ++i){
    		t = min(a[i] / 4, four);
    		four -= t;
    		a[i] -= t * 4;
    		if (four == 0){
    			break;
    		}
    	}
    	//把剩余的四连座分解为一个双座和一个单座
    	two += four;
    	one = four;
    	four = 0;
    	//再往1,2  7,8上安排士兵
    	for (int i = 0; i < k; ++i){
    		t = min(a[i] / 2, two);
    		two -= t;
    		a[i] -= t * 2;
    		if (two == 0){
    			break;
    		}
    	}
    	int s = 0;
    	//统计剩余士兵数量(每个group最多还剩一名士兵)
    	for (int i = 0; i < k; ++i){
    		s += a[i];
    	}
    	//单人座和双人座都还能坐一个士兵,若无法坐下全部士兵,则没有满足题意的策略
    	bool status = (s <= (two + one));
    	printf("%s
    ", status ? "YES": "NO");
    	return 0;
    }
    
  • 相关阅读:
    JS
    JS
    JS
    VUE
    element-ui 进入页面 message 自动触发的问题
    JS-数组中常用的方法
    CSS-transition简单过渡动画
    vue
    JS
    2021要买的书籍
  • 原文地址:https://www.cnblogs.com/lucianosimon/p/7390117.html
Copyright © 2011-2022 走看看