CF #250 div2

2014-06-02 02:03:12

总结:A题题意理解有误,耽误了点时间- -!,B题不难,但思路整理花了太多时间,还runtime error了一次,囧!后来就半小时看C了,想来是个简单题,结束后才A

A:(写的好挫TAT)

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int maxn = 100;

int main(){
    char a[maxn + 5],b[maxn + 5],c[maxn + 5],d[maxn + 5];
    int len[5],flag[5],flag1[5],flag2[5];
    memset(flag,0,sizeof(flag));
    memset(flag1,0,sizeof(flag1));
    memset(flag2,0,sizeof(flag2));
    scanf("%s%s%s%s",a,b,c,d);
    len[1] = strlen(a) - 2;
    len[2] = strlen(b) - 2;
    len[3] = strlen(c) - 2;
    len[4] = strlen(d) - 2;
    for(int i = 1; i <=4 ;i++){
        for(int j = 1; j <= 4; j++){
            if(len[i] <= len[j] / 2) flag1[i]++;
            if(len[i] >= len[j] * 2) flag2[i]++;
        }
    }
    int cnt = 0,mark;
    for(int i = 1; i <= 4; i++){
        if(flag1[i] == 3 || flag2[i] == 3){
            flag[i] = 1;
            cnt++;
            mark = i;
        }
    }
    if(cnt == 1){
        if(mark == 1) printf("A");
        else if(mark == 2) printf("B");
        else if(mark == 3) printf("C");
        else printf("D");
    }
    else{
        printf("C");
    }
    printf("\n");
    return 0;
}

B:(思路搞了好久,囧,弱菜)

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int n[20][100005],num[100005],ncnt[20];

int main(){
    int sum,m,maxb = 0;
    scanf("%d %d",&sum,&m);
    int temp = m;
    while(temp >= 1){
        ++maxb;
        temp >>= 1;
    }

    for(int i = 1; i <= m; ++i){
        int k = i & -i;
        int tn = 0;
        while(k >= 1){
            tn++;
            k >>= 1;
        }
        n[tn][ncnt[tn]++] = i;
    }
    //ncnt中记录个数
    int numcnt = 0;
    for(int i = maxb; i >= 1; --i){
        int v = 1 << (i - 1);

        while(sum >= v && ncnt[i] > 0){
            --ncnt[i];
            sum -= v;
            num[numcnt++] = n[i][ncnt[i]];
        }
    }
    if(sum != 0){
        printf("-1\n");
    }
    else{
        printf("%d\n",numcnt);
        printf("%d",num[0]);
        for(int i = 1; i < numcnt; ++i){
            printf(" %d",num[i]);
        }
        puts("");
    }

    return 0;
}

C:(呵呵,理清思路之后灰常简单)

#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 1000;

int v[maxn + 5];

int main(){
    int n,m,sum = 0;
    scanf("%d %d",&n,&m);
    
    for(int i = 1; i <= n; ++i){
        scanf("%d",&v[i]);
    }
    int a,b;
    for(int i = 1; i <= m; ++i){
        scanf("%d %d",&a,&b);
        sum += min(v[a],v[b]);
    }
    printf("%d\n",sum);

    return 0;
}

D、E(囧,E的几何题防AK了。。。。略过,喵)

 

posted @ 2014-06-02 02:12  Naturain  阅读(106)  评论(0编辑  收藏  举报