夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

JOIっぽいやつとか。。。

くだらないミスとか、問題の解釈違いやらやたらと多かったです。
とりあえず予選は以下といてないので頑張る。

0503 0504 0524 0525 0526
0534 0535 0536 0537 0547
0548 0557 0558 0559

0030

いきなりJOIじゃなかったw

#include <cstdio>
int dfs(int n, int s, int cnt, int sum, int num) {
	int res = 0;
	if (cnt==n&&sum==s) return 1;
	else if (cnt==n) return 0;
	if (num==10) return 0;
	res += dfs(n, s, cnt+1, sum+num, num+1);
	res += dfs(n, s, cnt, sum, num+1);
	return res;
}
int main() {
	int n, s;
	while (scanf("%d%d",&n,&s)) {
		if (n==0&&s==0) break;
		int res = dfs(n, s, 0, 0, 0);
		printf("%d\n",res);
	}
}

0035

#include <cstdio>
#include <iostream>
using namespace std;
bool check(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
    if (x1!=x2) {
        double m = (y2-y1)/(x2-x1);
        if (y3-y1>m*(x3-x1)&&y4-y1<m*(x4-x1)) return true;
        else if (y3-y1<m*(x3-x1)&&y4-y1>m*(x4-x1)) return true;
        else return false;
    } else {
        if (x3>x1&&x4<x1) return true;
        else if (x3<x1&&x4>x1) return true;
        else return false;
    }
}
int main() {
    double xa,ya,xb,yb,xc,yc,xd,yd;
    while (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF) {
        if (check(xa,ya,xc,yc,xb,yb,xd,yd)&&check(xb,yb,xd,yd,xa,ya,xc,yc)) puts("YES");
        else puts("NO");
    }
}

0036

#include <iostream>
using namespace std;
/*
A 11 B 1 C 1111 D 01 E 110 F 10 G 011
  11   1          11   011   11   110
       1          10         01
       1
*/
int main() {
    string map[8], in;
    while (cin>>in) {
        map[0]=in;
        int h;
        string key[4];
        if (in=="00000000") h=0;
        else {
            key[0]=in;
            h=1;
        }
        for (int i=1; i<8; i++) {
            cin>>map[i];
            if (map[i]!="00000000") key[h++]=map[i];
        }
        if (h==4) cout<<"B"<<endl;
        else if (h==1) cout<<"C"<<endl;
        else if (h==3) {
            bool flag=true;
            for (int i=0; i<8; i++) if (key[1][i]=='1') {
                if (key[0][i]=='1') flag=false;
                break;
            }
            if (flag) cout<<"D"<<endl;
            else cout<<"F"<<endl;
        } else {
            bool flag=true;
            for (int i=0; i<8; i++) if (key[0][i]=='1') {
                if (key[1][i]=='0') flag=false;
                break;
            }
            if (flag) {
                for (int i=0; i<8; i++) if (key[1][i]=='1') {
                    if (key[0][i]=='0') flag=false;
                    break;
                }
                if (flag) cout<<"A"<<endl;
                else cout<<"G"<<endl;
            } else {
                cout<<"E"<<endl;
            }
        }
    }
}

0544

くだらないミスをしていた。

#include <cstdio>
#include <vector>
using namespace std;
int main() {
    int N,M;
    while (scanf("%d%d",&N,&M)) {
        if (N==0&&M==0) break;
        vector<int> map(N);
        for (int i=0; i<N; i++) scanf("%d",&map[i]);
        int res=0,tmp,cnt=0;
        bool flag=true;
        for (int i=0; i<M; i++) {
            scanf("%d",&tmp);
            if (flag) {
                res+=tmp;
                if (res<N-1) {
                    res+=map[res]; cnt++;
                    if (res>=N-1) flag=false;
                } else if (res>=N-1) {
                    cnt++;
                    flag=false;
                }
            }
        }
        printf("%d\n",cnt);
    }
}

0545

#include <cstdio>
#include <set>
#include <vector>
using namespace std;
int main() {
    int n, m;
    while (scanf("%d%d",&n,&m)) {
        if (n==0&&m==0) break;
        vector<int> friends[n];
        for (int i=0; i<m; i++) {
            int a,b; scanf("%d%d",&a,&b);
            friends[a-1].push_back(b-1);
            friends[b-1].push_back(a-1);
        }
        set<int> s;
        for (int i=0; i<friends[0].size(); i++) {
            s.insert(friends[0][i]);
            for (int j=0; j<friends[friends[0][i]].size(); j++) {
                if (friends[friends[0][i]][j]!=0) s.insert(friends[friends[0][i]][j]);
            }
        }
        printf("%d\n",s.size());
    }
}

0523

#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (n==0) break;
        int taro[n], hana[n], t=0, h=0, ut=n, uh=n, turn=1;
        bool usedt[n], usedh[n];
        for (int i=0; i<n; i++) scanf("%d",&taro[i]);
        sort(taro, taro+n);
        fill(usedt, usedt+n, true);
        fill(usedh, usedh+n, true);
        for (int i=1; i<=2*n; i++) {
            if (taro[t]==i) t++;
            else hana[h++]=i;
        }
        // for (int i=0; i<n; i++) printf("%d %d\n",taro[i],hana[i]);
        t=0; h=0;
        while (ut>0&&uh>0) {
            if (turn) {
                bool flag=true; ut--;
                usedt[t]=false;
                // printf("%d\n",taro[t]);
                for (;h<n; h++) if (taro[t]<hana[h]&&usedh[h]) {
                    flag=false;
                    turn=0;
                    break;
                }
                if (flag) {
                    for (t=0; t<n; t++) if (usedt[t]) break;
                    h=0;
                }
            } else {
                bool flag=true; uh--;
                usedh[h]=false;
                // printf("%d\n",hana[h]);
                for (;t<n; t++) if (hana[h]<taro[t]&&usedt[t]) {
                    flag=false;
                    turn=1;
                    break;
                }
                if (flag) {
                    for (h=0; h<n; h++) if (usedh[h]) break;
                    t=0;
                }
            }
        }
        printf("%d\n%d\n",uh,ut);
    }
}