読者です 読者をやめる 読者になる 読者になる

YNU.cpc

横浜国立大学競技プログラミング部 ( YNU.cpc )

活動日記 day 35

活動内容 :
部活動紹介
コンテスト (チーム戦)
コンテスト : Virtual Arena: Room 3408

A - Water Rate

#include <iostream>
#include <algorithm>
 
using namespace std;
 
int A = 0, B = 0;
int C = 0, D = 0;
int P = 0;
 
int main(void){
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    cin >> P;
 
    int x = A * P;
    int y = (P <= C) ? B : B + D*(P-C);
 
    cout << min(x,y) << endl;
}

B - Christmas Party

#include <iostream>
#include <vector>
 
using namespace std;
 
int N = 0;
int M = 0;
 
int main(void){
    cin >> N;
    cin >> M;
 
    vector<int> A(M, 0);
    vector<int> P(N, 0);
 
    int target = 0;
    int count  = 0;
    int x = 0;
    int z = 0;
 
    for(int i=0; i<M; ++i){
        cin >> A[i];
    }
 
    for(int i=0; i<M; ++i){
        target = A[i];
 
        count = 0;
        for(int j=0; j<N; ++j){
            cin >> x;
 
            if(x == target){
                P[j] += 1;
                count++;
            }
        }
 
        P[target - 1] += (N - count);
    }
 
    for(int i=0; i<N; ++i){
        cout << P[i] << endl;
    }
}

C - Weather Forecaster

#include<iostream>
 
using namespace std;
 
int main(){
    //scanf("%d",&n);
    int h,w;
    cin>>h>>w;
    char cloud[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>cloud[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        int j=0;
            while(cloud[i][j] != 'c'&&j<w){
                cout << -1;
                j++;
                                if(j<w){
                    cout<<" ";
                }
            }
            int count = 0;
            while(j<w){
                if(cloud[i][j] == 'c'){
                    //int count = 0;
                    count=0;
                    cout<<count;
                }
                else{
                    count++;
                    cout<<count;
                }
                j++;
                if(j<w){
                    cout<<" ";
                }
            }
            cout << endl;
    }
    //input finish
    return 0;
}

D - Silk Road

#include <iostream>
#include <algorithm>
#include <climits>
 
using namespace std;
 
int N = 0, M = 0;
int D[1000] = {0};
int C[1000] = {0};
 
int memo[1001][1001];
 
long dp(int i, int j){
 
    if(memo[i][j] != -1){
        return memo[i][j];
    }
 
    if(j > M){
        return memo[i][j] = INT_MAX;
    }
    if(i == N){
        return memo[i][j] = 0;
    }
 
    long x = dp(i, j+1);
    long y = dp(i+1, j+1);
 
    if(x == INT_MAX && y == INT_MAX){
        return memo[i][j] = INT_MAX;
    }else if(x == INT_MAX){
        return memo[i][j] = C[j] * D[i] + y;
    }else if(y == INT_MAX){
        return memo[i][j] = x;
    }else{
        return memo[i][j] = min(x, C[j] * D[i] + y);
    }
 
}
 
int main(void){
 
    fill(memo[0],memo[1000], -1);
 
    cin >> N >> M;
    for(int i=0; i<N; ++i){
        cin >> D[i];
    }
    for(int j=0; j<M; ++j){
        cin >> C[j];
    }
    cout << dp(0, 0) << endl;
}

E - 3-Primes Problem

#include <iostream>
#include <climits>
#include <vector>
 
using namespace std;
int main()
{
    int prime[1000];
    for(int i=0;i<1000;i++){
        prime[i]=1;
    }
    prime[0] = 0;// 1 is not prime
    for (int i = 0; i < 1000; i++)
    {
        if (prime[i] == 1)
        {
            //cout<<"hogehoge"<<endl;
            for (int j = (i + 1); (i + 1) * j <= 1000; j++)
            {
                prime[(i + 1) * j - 1] = 0;
            }
        }
    }
    int count = 0;
    for(int i = 0; i < 1000; i++){
        if(prime[i] == 1){
            count++;
        }
    }
    int number[count], n = 0;
    for(int i = 0; i < 1000; i++){
        if(prime[i] == 1){
            number[n] = i + 1;
            n++;
        }
    }
    int t=0;
    cin>>t;
    vector<int> a(t, 0);
    for(int i=0;i<t;i++){
        cin>>a[i];
    }
    for(int i=0;i<t;i++){
        for(int j = 0; j < count; j++){
            for(int k = 0; k < count; k++){
                for(int l = 0; l < count; l++){
                    if(a[i] == number[j] + number[k] + number[l]){
                        cout << number[j] << " " << number[k] << " " << number[l] << endl;
                        goto LABEL;
                    }
                }
            }
        }
        LABEL:
        continue;
    }
    return 0;
}