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

夢追い人

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

01*8

タイトルのとおり01*8の糞問ばっかやった。

0128

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int n;
string res[8];
/*
 0123456789
0*****     
1     *****
2==========
3 **** ****
4* **** ***
5** **** **
6*** **** *
7**** **** 
*/
int main() {
    int flag=0;
    while (scanf("%d",&n)!=EOF) {
        if (flag) printf("\n");
        else flag=1;
        fill(res, res+8, "");
        res[2]="=====";
        int ten=10000;
        for (int i=0; i<5; i++) {
            int x=n/ten;
            n%=ten;
            ten/=10;
            if (0<=x&&x<=4) {
                res[0]+='*';
                res[1]+=' ';
            } else {
                res[0]+=' ';
                res[1]+='*';
            }
            if (x==0||x==5) res[3]+=' ';
            else res[3]+='*';
            if (x==1||x==6) res[4]+=' ';
            else res[4]+='*';
            if (x==2||x==7) res[5]+=' ';
            else res[5]+='*';
            if (x==3||x==8) res[6]+=' ';
            else res[6]+='*';
            if (x==4||x==9) res[7]+=' ';
            else res[7]+='*';
        }
        for (int i=0; i<8; i++) cout << res[i] << endl;
    }
}

0138

#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
struct P {
double first;
int second;
};
class great {
public:
    bool operator()(const P& a, const P& b) {
        return a.first<b.first;
    }
};
P team1[8], team2[8], team3[8];
P amari[18];
int main() {
    for (int i=0; i<8; i++)
        scanf("%d%lf",&team1[i].second,&team1[i].first);
    for (int i=0; i<8; i++)
        scanf("%d%lf",&team2[i].second,&team2[i].first);
    for (int i=0; i<8; i++)
        scanf("%d%lf",&team3[i].second,&team3[i].first);
    sort(team1, team1+8, great());
    sort(team2, team2+8, great());
    sort(team3, team3+8, great());
    for (int i=2; i<8; i++) amari[i-2]=team1[i];
    for (int i=2; i<8; i++) amari[i+4]=team2[i];
    for (int i=2; i<8; i++) amari[i+10]=team3[i];
    sort(amari, amari+18, great());
    printf("%d %.2lf\n%d %.2lf\n",team1[0].second,team1[0].first,
                                  team1[1].second,team1[1].first);
    printf("%d %.2lf\n%d %.2lf\n",team2[0].second,team2[0].first,
                                  team2[1].second,team2[1].first);
    printf("%d %.2lf\n%d %.2lf\n",team3[0].second,team3[0].first,
                                  team3[1].second,team3[1].first);
    printf("%d %.2lf\n%d %.2lf\n",amari[0].second,amari[0].first,
                                  amari[1].second,amari[1].first);
}

0158

#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
int n;
int dp[1000001];
queue<P> que;
int main() {
    memset(dp, 0, sizeof(dp));
    que.push(P(2,1));
    while (!que.empty()) {
        P p=que.front(); que.pop();
        if (dp[p.first]) continue;
        dp[p.first]=p.second;
        if (p.first!=4&&(p.first-1)%3==0&&((p.first-1)/3)%2) {
            que.push(P((p.first-1)/3,p.second+1));
        }
        if (p.first*2<1000001) {
            que.push(P(p.first*2,p.second+1));
        }
    }
    // for (int i=1; i<=10; i++) printf("%d%c",dp[i],i==10?'\n':' ');
    while (scanf("%d",&n)) {
        if (!n) break;
        printf("%d\n",dp[n]);
    }
}

0188

#include <cstdio>
#include <cmath>
int n, x;
int a[100];
int main() {
    while (scanf("%d",&n)) {
        if (!n) break;
        for (int i=0; i<n; i++) scanf("%d",&a[i]);
        scanf("%d", &x);
        int lb=0, ub=n-1, res=0;
        while (ub>=lb) {
            res++;
            int mid=floor((lb+ub)/2);
            if (a[mid]<x) {
                lb=mid+1;
            } else if (a[mid]>x) {
                ub=mid-1;
            } else {
                break;
            }
        }
        printf("%d\n",res);
    }
}
広告を非表示にする