The 36th ACM/ICPC Asia Regional Shanghai Site —— Warmup

来源:互联网 发布:csgo优化参数 编辑:程序博客网 时间:2024/05/08 06:38
 Pro1001.  Working in Beijing

容易知道,每一次重要会议他一定要在上海,所以他一定会有N * C 的基本费用(B, C 定义详见程序),另外,他一开始是在北京和最后也是在北京,所以基本费用又有 2 * B;对于相邻的两个会议而言,如果从第一个会议到第二个会议他坐了飞机(两次),比在这中间的时间在北京赚钱要多,那么他可以选择不去北京,反之亦然。

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long i64d;int A[100000 + 2];int nA, B, C;i64d calc(){    i64d ans = (i64d)nA * C + 2LL * B;    for(int i = 0; i + 1 < nA; ++i)        ans += min((i64d)(A[i + 1] - A[i] - 1) * (i64d)C, 2LL * B);    return ans;}int main(){    //freopen("data.in", "r", stdin);    int nT, idx = 0; scanf("%d", &nT);    while( (nT --) > 0 ) {        scanf("%d %d %d", &nA, &B, &C);        for(int i = 0; i < nA; ++i) scanf("%d", A + i);        printf("Case #%d: %I64d\n", ++idx, calc());    }    return 0;}


Pro1005. Mario and Mushrooms

猜吧,不是罪。

#include<cstdio>int main(){    int idx = 0, nT, m, k;    scanf("%d", &nT);    while( (nT --) > 0 ) {         scanf("%d %d", &m, &k);         printf("Case #%d: %.8lf\n", ++idx, 1.0 / (k * m + k + 1.0));    }    return 0;}


Pro1008. Parsing URL

 模拟在细心。

#include<cstdio>#include<cstring>char str[10086];int main(){    //freopen("data.in", "r", stdin);    int nT, idx = 0; scanf("%d", &nT);    while( (nT --) > 0 ) {        scanf("%s", str);        printf("Case #%d: ", ++idx);        int s, e;        for(s = 0; str[s]; ++s) if( str[s] == '/' && str[s + 1] != '/' ) break;        for(e = s + 1; str[e]; ++e) if( str[e] == ':' || str[e] == '/' ) break;        for(int i = s + 1; i < e; ++i) printf("%c", str[i]); puts("");    }    return 0;}


Pro1010. Ads Proposal

采用树状数组,C++,AC,1406MS,不用多说,学过树状数组,应该知道怎么用在这里了。

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long i64d;const int maxN = 100000 + 2;const int maxM = 500000 + 2;struct node{    int U, C; i64d L;    inline void in() { scanf("%d %d %I64d", &U, &C, &L); }    inline bool operator<(const node &s) const { return C > s.C; }};node A[maxM];int N, M, Q;int rank[maxN];i64d Len[maxM];int lowbit(int x) { return x & (-x); }void update(int pos, i64d val){    while( pos <= M ) {        Len[pos] += val;        pos += lowbit(pos);    }}i64d sum(int pos){    i64d sum = 0LL;    while( pos > 0 ) {        sum += Len[pos];        pos -= lowbit(pos);    }    return sum;}int main(){    //freopen("data.in", "r", stdin);    int idx = 0, nT; scanf("%d", &nT);    while( (nT --) > 0 ) {        scanf("%d %d %d", &N, &M, &Q);        for(int i = 0; i < M; ++i) A[i].in();        sort(A, A + M);        //memset(rank, 0, sizeof(rank));        //memset(Len, 0, sizeof(Len));        for(int i = 0; i <= N; ++i) rank[i] = 0;        for(int i = 0; i <= M; ++i) Len[i] = 0;        for(int i = 0; i < M; ++i) {            ++rank[A[i].U];            update(rank[A[i].U], A[i].L);        }        int pos; printf("Case #%d:\n", ++idx);        for(int i = 0; i < Q; ++i) {            scanf("%d", &pos);            if( pos > M ) pos = M;            printf("%I64d\n", sum(pos));        }    }    return 0;}


 

 

 

 

 

 

原创粉丝点击