夢追い人

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

ひどい・・・

色々とひどいのでノーコメントで

1724

#include <cstdio>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int k, n, r;
struct road {
    int d, l, t;
};
bool vis[100][10001];
vector<road> roads[100];
int main() {
    scanf("%d%d%d",&k,&n,&r);
    memset(vis, 0, sizeof(vis));
    for (int i=0; i<r; i++) {
        int s, de, l, t;
        scanf("%d%d%d%d",&s,&de,&l,&t);
        roads[s-1].push_back((road){de-1,l,t});
    }
    priority_queue<PP, vector<PP>, greater<PP> > que;
    que.push(make_pair(0,P(0,0)));
    while (!que.empty()) {
        int len=que.top().first;
        int np=que.top().second.first;
        int sp=que.top().second.second;
        que.pop();
        if (vis[np][sp]) continue;
        vis[np][sp]=true;
        if (np==n-1) {
            printf("%d\n",len);
            return 0;
        }
        for (int i=0; i<roads[np].size(); i++) {
            road nr=roads[np][i];
            if (sp+nr.t>k||vis[nr.d][sp+nr.t]) continue;
            que.push(make_pair(len+nr.l,P(nr.d,sp+nr.t)));
        }
    }
    puts("-1");
}

1731

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
string s;
int main() {
    cin>>s;
    sort(s.begin(), s.end());
    do {
        cout<<s<<endl;
    } while (next_permutation(s.begin(), s.end()));
}

1828

#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
int n;
pair<int, int> p[50000];
int main() {
    while (scanf("%d",&n)) {
        if (n==0) break;
        for (int i=0; i<n; i++) {
            scanf("%d%d",&p[i].first,&p[i].second);
        }
        sort(p, p+n, greater<pair<int, int> >());
        int res=1, ymax=p[0].second;
        for (int i=1; i<n; i++) {
            if (ymax<p[i].second) {
                res++;
                ymax=p[i].second;
            }
        }
        printf("%d\n",res);
    }
}
広告を非表示にする