夢追い人

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

Codeforces#113

1295->1311(+16)
一完でした。
いや二完できたんだけど・・・みすった・・・

Codefoces A

やるだけ

#include <cstdio>
#include <algorithm>
using namespace std;
struct S {
    int p, t;
    S () {}
    S (int p, int t) : p(p), t(t) {}
};
bool comp(const S& a, const S& b) {
    if (a.p!=b.p) return a.p>b.p;
    return a.t<b.t;
}
S score[50];
int main() {
    int n, k; scanf("%d%d",&n,&k);
    for (int i=0; i<n; i++) scanf("%d%d",&score[i].p,&score[i].t);
    sort(score, score+n, comp);
    int res=0;
    int rank=0;
    int cnt=0;
    S bef=S(-1,-1);
    for (int i=0; i<n; i++) {
        if (bef.p!=score[i].p||bef.t!=score[i].t) {
            if (rank+cnt>=k&&k>=rank) {
                res=cnt;
                break;
            }
            bef=score[i];
            rank+=cnt;
            cnt=1;
        } else {
            cnt++;
        }
    }
    if (rank+cnt>=k&&k>=rank) res=cnt;
    printf("%d\n",res);
}

Codeforces E

DPやるだけ
パスタそのもの
漏れておわった

#include <cstdio>
#include <iostream>
using namespace std;
#define mod 1000000007
typedef long long ll;
ll dp[2][4]; // 0-D, 1-A, 2-B, 3-C
int main() {
    int n; scanf("%d",&n);
    dp[0][0]=1;
    for (int i=1; i<=n; i++) {
        dp[i&1][0]=(dp[(i-1)&1][1]+dp[(i-1)&1][2]+dp[(i-1)&1][3])%mod;
        dp[i&1][1]=(dp[(i-1)&1][0]+dp[(i-1)&1][2]+dp[(i-1)&1][3])%mod;
        dp[i&1][2]=(dp[(i-1)&1][0]+dp[(i-1)&1][1]+dp[(i-1)&1][3])%mod;
        dp[i&1][3]=(dp[(i-1)&1][0]+dp[(i-1)&1][1]+dp[(i-1)&1][2])%mod;
    }
    cout<<dp[n&1][0]<<endl;
}

Codeforces C

よくわからない・・・WA

Codeforces B

もはやライブラリゲーとなってた幾何問題
よくない
ジャッジ待ち→WAだった・・・

#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#define EPS 1e-10
using namespace std;
double add(double a, double b) {
    if (abs(a+b)<EPS*(abs(a)+abs(b))) return 0;
    return abs(a+b);
}
struct P {
    double x, y;
    P () {}
    P (double x, double y) : x(x), y(y) {}
    P operator + (P p) {
        return P(add(x,p.x),add(y,p.y));
    }
    P operator - (P p) {
        return P(add(x,-p.x),add(y,-p.y));
    }
    P operator * (P p) {
        return P(x*p.x,y*p.y);
    }
    P operator / (double n) {
        return P(x/n, y/n);
    }
    double dot(P p) {
        return add(x*p.y,y*p.x);
    }
    double det(P p) {
        return add(x*p.y,-y*p.x);
    }
};
P A[100000], B[100000];
int an, bn;
int convex_contains(P p) {
    P g=(A[0]+A[an/3]+A[2*an/3])/3.0;
    int a=0, b=an;
    while (a+1<b) {
        int c=(a+b)/2;
        if ((A[a]-g).det(A[c]-g)>0) {
            if ((A[a]-g).det(p-g)>0&&(A[c]-g).det(p-g)<0) b=c;
            else a=c;
        } else {
            if ((A[a]-g).det(p-g)<0&&(A[c]-g).det(p-g)>0) a=c;
            else b=c;
        }
    }
    b %= an;
    if ((A[a]-p).det(A[b]-p)<0) return 0;
    if ((A[a]-p).det(A[b]-p)>0) return 2;
    return 1;
}
int main() {
    scanf("%d",&an);
    for (int i=0; i<an; i++) {
        int x, y; scanf("%d%d",&x,&y);
        A[i]=P((double)x,(double)y);
    }
    scanf("%d",&bn);
    for (int i=0; i<bn; i++) {
        int x, y; scanf("%d%d",&x,&y);
        B[i]=P((double)x,(double)y);
    }
    for (int i=0; i<bn; i++) {
        if (convex_contains(B[i])!=2) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

KOJ 0002

実はやるだけだった

#include <cstdio>
#include <iostream>
using namespace std;
string str, ans;
bool isthree() {
    int sum=0;
    for (int i=0; i<str.length(); i++) {
        sum+=str[i]-'0';
    }
    if (sum%3==0) return true;
    return false;
}
bool isfive() {
    char c=str[str.length()-1];
    if (c=='5'||c=='0') return true;
    return false;
}
int main() {
    while (cin>>str>>ans) {
        if (str=="0"&&ans=="0") break;
        bool o1=isthree(), o2=isfive();
        if (o1&&o2&&ans=="FizzBuzz") {
            puts("OK");
        } else if (o1&&!o2&&ans=="Fizz") {
            puts("OK");
        } else if (!o1&&o2&&ans=="Buzz") {
            puts("OK");
        } else if (!o1&&!o2&&ans==str) {
            puts("OK");
        } else {
            puts("NG");
        }
    }
}

AOJ 2259

やるだけ

#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int m, n; scanf("%d%d",&m,&n);
    int M=-1;
    for (int i=0; i<m; i++) {
        int sum=0;
        for (int j=0; j<n; j++) {
            int s; scanf("%d",&s);
            sum+=s;
        }
        M=max(M,sum);
    }
    printf("%d\n",M);
}

まとめ

ジャッジ早くしろ