USACO Training Section1.1

/*
ID: vevina01
PROG: test
LANG: C++
*/
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;

int a,b;

int main(){
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    scanf("%d",&a);
    scanf("%d",&b);
    printf("%d\n",a+b);
    return 0;
}

/*
ID: vevina01
PROG: ride
LANG: C++
*/
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;

char a[7],b[7];

int main(){
    freopen("ride.in","r",stdin);
    freopen("ride.out","w",stdout);
    scanf("%s",a);
    cin.get();
    scanf("%s",b);
    int aa = 1;
    int bb = 1;
    int len_a = strlen(a);
    int len_b = strlen(b);
    for(int i = 0; i < len_a; i ++)
        aa = aa * (a[i] - 'A' + 1) % 47;
    for(int i = 0; i < len_b; i ++)
        bb = bb * (b[i] - 'A' + 1) % 47;

    if(aa == bb)
        printf("GO\n");
    else
        printf("STAY\n");
    return 0;
}

/*
ID: vevina01
PROG: gift1
LANG: C++
*/
#include <cstring>
#include <cstdio>
#include <map>
#include <iostream>
using namespace std;

int np;
char p[12][16];
int init[12];
int now[12];
char tmp[12];
int total, num;

inline int get_num(char a[]){
    int len1,len = strlen(a),i,j;
    for(i = 0; i < np; i++){
        len1 = strlen(p[i]);
        if(len1 == len){
            for(j = 0; j < len; j ++){
                if(a[j] != p[i][j]) break;
            }
        }
        if(j == len) return i;
    }
}

int main(){
    freopen("gift1.in","r",stdin);
    freopen("gift1.out","w",stdout);
    scanf("%d",&np);
    for(int i = 0; i < np; i ++){
        cin.get();
        scanf("%s",p[i]);
    }

    memset(now,0,sizeof(now));
    for(int i = 0; i < np; i ++){
        cin.get();
        scanf("%s",tmp);
        int give = get_num(tmp);
        scanf("%d%d",&total,&num);
        init[give] = total;
        for(int j = 0; j < num; j ++){
            cin.get();
            scanf("%s",tmp);
            int get = get_num(tmp);
            now[get] = now[get] + total / num;
        }
        if(num == 0) now[give] = now[give] + total;
        else now[give] = now[give] + total - total / num * num;
    }

    for(int i = 0; i < np; i ++)
        printf("%s %d\n",p[i], now[i] - init[i]);

    return 0;
}

/*
ID: vevina
PROG: friday
LANG: C++
*/
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;

int n;
int ans[7];

inline bool isLeap(int year){
    if(year % 4 != 0) return false;
    else if(year % 100 != 0) return true;
    else if(year % 400 == 0) return true;
    else return false;
}

int main(){
    freopen("friday.in","r",stdin);
    freopen("friday.out","w",stdout);
    scanf("%d",&n);
    memset(ans, 0, sizeof(ans));
    int year = 1900;
    int month = 1;
    bool pcount;
    int date = 6;
    ans[date] ++;
    while(year < 1900 + n){
        if(isLeap(year)) pcount = true;
        else pcount = false;
        while(month <= 12){
            if(month == 2){
                if(pcount){
                    date = (date + 29) % 7;
                }
                else{
                    date = (date + 28) % 7;
                }
            }
            else if(month == 4 || month == 6 || month == 9 || month == 11){
                date = (date + 30) % 7;
            }
            else{
                date = (date + 31) % 7;
            }
            ans[date]++;
            month ++;
        }
        month = 1;
        year ++;
    }
    ans[date] --;
    printf("%d",ans[6]);
    for(int i = 0; i < 6; i ++)
        printf(" %d", ans[i]);
    printf("\n");
    return 0;
}

/*
ID: vevina01
PROG: beads
LANG: C++
*/
#include <cstring>
#include <cstdio>
#include <iostream>
using namespace std;

int n;
char a[500];
bool ispos[500];
int max_ans;

inline int go(int x){
    int tmp = 0;
    int now = x;
    while(!ispos[now] && a[now] == 'w'){
        tmp ++;
        ispos[now] = true;
        now ++;
        if(now >= n) now = now - n;
    }
    x = now;
    while(!ispos[now] && (a[now] == a[x] || a[now] == 'w')){
        tmp ++;
        ispos[now] = true;
        now ++;
        if(now >= n) now = now - n;
    }
    return tmp;
}

inline int goback(int x){
    int tmp = 0;
    int now = x;
    while(!ispos[now] && a[now] == 'w'){
        tmp ++;
        ispos[now] = true;
        now --;
        if(now < 0) now = n - 1;
    }
    x = now;
    while(!ispos[now] && (a[now] == a[x] || a[now] == 'w')){
        tmp ++;
        ispos[now] = true;
        now --;
        if(now < 0) now = now - n;
    }
    return tmp;
}


int main(){
    freopen("beads.in","r",stdin);
    freopen("beads.out","w",stdout);
    scanf("%d",&n);
    cin.get();
    scanf("%s",a);
    max_ans = 0;
    memset(ispos,false,sizeof(ispos));
    int tt = go(0);
    int tt1 = goback(n-1);
    if(tt + tt1 > max_ans) max_ans = tt + tt1;
    for(int i = 1; i < n; i++){
        memset(ispos,false,sizeof(ispos));
        tt = go(i);
        tt1 = goback(i - 1);
        if(tt + tt1 > max_ans) max_ans = tt + tt1;
    }
    printf("%d\n",max_ans);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值