Codeforces Round #556 (Div. 2)

A

贪心

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
using namespace std;
const int N = 1005;
int a[N], b[N];
int n, m, bou, res;
inline bool rule(int x, int y){
    return x > y;
}
int main(){
    scanf("%d%d%d", &n, &m, &bou);
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for(int i = 1; i <= m; ++i) scanf("%d", &b[i]);
    sort(a + 1, a + n + 1); sort(b + 1, b + m + 1, rule);
    int cnt = b[1] > a[1] ? bou / a[1] : 0;
    res = cnt * b[1] - cnt * a[1] + bou; 
    printf("%d", res);
    return 0;
}

B

贪心。。

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
using namespace std;
const int N = 55;
int n;
bool map[N][N], col[N][N];
inline void print(int x, int y){
    if(!(map[x][y] & map[x + 1][y] & map[x + 1][y - 1]
     & map[x + 1][y + 1] & map[x + 2][y])){
        printf("NO\n"); exit(0);
    }
    map[x][y] = map[x + 1][y] = map[x + 1][y - 1]
    = map[x + 1][y + 1] = map[x + 2][y] = 0;
}
int main(){
    scanf("%d", &n);
    char str[N];
    for(int i = 1; i <= n; ++i){
        scanf("%s", str + 1);
        for(int j = 1; j <= n; ++j){
            map[i][j] = (str[j] == '.');
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            if(map[i][j]) print(i, j);
        }
    }
    printf("YES\n");
    return 0;
}

C

贪心??。。。
先放2 再放1 再放所有2 再放所有1

#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int n, cnt1, cnt2;
int main(){
    scanf("%d", &n);
    for(int i = 1, x; i <= n; ++i){
        scanf("%d", &x);
        if(x == 1) ++cnt1; else ++cnt2;
    }
    if(cnt1 == 0){
        for(int i = 1; i <= cnt2; ++i) putchar('2'), putchar(' ');
        return 0;
    }
    if(cnt2 == 0){
        for(int i = 1; i <= cnt1; ++i) putchar('1'), putchar(' ');
        return 0; 
    }
    putchar('2'), putchar(' '), putchar('1'), putchar(' ');
    for(int i = 2; i <= cnt2; ++i) putchar('2'), putchar(' ');
    for(int i = 2; i <= cnt1; ++i) putchar('1'), putchar(' ');   
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/hjmmm/p/10794309.html