ACM-ICPC 2018 南京赛区网络预赛 - C GDY (模拟)

诶,比赛时差一点就debug出来了

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 14;
map<int,int> vz[205];

LL ans[205];

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int T,cas=1; scanf("%d",&T);
    while(T--){
        int N,M; scanf("%d %d",&N, &M);
        queue<int> Q;
        for(int i=1;i<=M;++i){
            int tmp;
            scanf("%d",&tmp);
            if(tmp<=2) tmp+=13;
            Q.push(tmp);
        }
        for(int i=1;i<=N;++i){
            int cnt = 0;
            while(!Q.empty() && cnt<5){
                cnt++;
                int x = Q.front(); Q.pop();
                vz[i][x]++;
            }
        }
        int win;
        int last=-1,cur=0,pp=-1;
        bool epy = false;
        if(Q.empty()){
            epy = true;
        }
        while(true){
            map<int,int> ::iterator it;
            bool ed = false;
            for(int i=1;i<=N;++i){
                if(i==pp){                  //轮了一圈没人出牌,摸牌
                    last = -1;
                    for(int j=0;j<N && !epy;++j){
                        int now = i+j;
                        if(now>N) now-=N;
                        int x = Q.front(); Q.pop();
                        vz[now][x]++;
                        if(Q.empty()) epy = true;
                    }
                }
                if(last == 15) continue;
                bool chu = false;
                for(it =vz[i].begin();it!=vz[i].end();++it){
                    if(it->second==0) continue;
                    int tmp=  it->first;
                    if(last==-1 || tmp==last+1 || tmp==15){
                        cur = tmp;
                        pp = i;
                        vz[i][tmp]--;
                        chu = true;
                        break;
                    }
                }
                if(!chu) continue;              //没有出牌

                last = cur;
                bool zero = true;
                for(it = vz[i].begin();it!=vz[i].end();++it){
                    if(!it->second) continue;
                    else{
                        zero = false;
                        break;
                    }
                }
                if(zero){
                    ed = true;
                    win = i;
                    break;
                }
            }
            if(ed){         //有人出完了
                break;
            }
        }

        printf("Case #%d:\n",cas++);
        for(int i=1;i<=N;++i){
            ans[i] = 0;
            if(i==win){
                printf("Winner\n");
            }
            else{
                map<int,int> :: iterator it;
                for(it = vz[i].begin();it!=vz[i].end();++it){
                    int tmp = it->first;
                    if(tmp>13) tmp-=13;
                    ans[i] += (LL)tmp*(it->second);
                }
                printf("%lld\n",ans[i]);
            }
            vz[i].clear();
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/xiuwenli/p/9571705.html

时间: 2024-11-06 19:54:50

ACM-ICPC 2018 南京赛区网络预赛 - C GDY (模拟)的相关文章

ACM-ICPC 2018 南京赛区网络预赛 E题

ACM-ICPC 2018 南京赛区网络预赛 E题 题目链接: https://nanti.jisuanke.com/t/30994 Dlsj is competing in a contest with n (0 < n \le 20)n(0<n≤20) problems. And he knows the answer of all of these problems. However, he can submit ii-th problem if and only if he has s

ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树

目录 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 题意 思路 ACM-ICPC 2018 南京赛区网络预赛 Lpl and Energy-saving Lamps 线段树 题面 During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Dragon imprisoned Lpl in the

ACM-ICPC 2018 南京赛区网络预赛 J.Sum

Sum A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 is a square number. Some integers could be decomposed into

ACM-ICPC 2018 南京赛区网络预赛 L. Magical Girl Haze

262144K There are NN cities in the country, and MM directional roads from uu to v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance c_ici?. Haze is a Magical Girl that lives in City 11, she can choose no more than KK roads and make their distances

计蒜客 ACM-ICPC 2018 南京赛区网络预赛 A. An Olympian Math Problem-数学公式题

A. An Olympian Math Problem 54.28% 1000ms 65536K Alice, a student of grade 66, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him.

线性素数筛 ACM-ICPC 2018 南京赛区网络预赛 J Sum

https://www.jisuanke.com/contest/1555?view=challenges 题意: 题解:写完都没发现是个积性函数233 想法就是对x分解质因数,f(x)就是2^k,其中k是x分解结果中次数为一的质因子个数.如果有某个次数大于等于3,f(x)==0; 这样明显会TLE 所以就想一个递推的方法. 于是魔改了一下线性筛. #include<iostream> #include<cstdlib> #include<cstdio> #includ

ACM-ICPC 2018 南京赛区网络预赛 做题记录

比赛的时候被J题卡常然后B题自闭最后G题没调完 5题gg 现在补题进度:6/12 A. 题解: 高考数学题,裂项完之后答案就是n!-1 (n!)%n=0,所以就是n-1 1 #include<bits/stdc++.h> 2 #define ll long long 3 using namespace std; 4 int T; 5 ll n; 6 int main() 7 { 8 cin>>T; 9 while(T--) 10 { 11 cin>>n; 12 cout

ACM-ICPC 2018 南京赛区网络预赛 K. The Great Nim Game

题意:有N堆石子(N为大数),每堆的个数按一定方式生成,问先手取若干堆进行尼姆博弈,必胜的方式有多少种. 题解:因为 k < 4096,所以出现的数最多只有4096个,对每个数字只考虑出现奇/偶次进行dp,答案是所有不等于0的dp值的和.然后如果一个数字出现x次,它对自己出现奇数次的方案数和偶数次的方案数贡献都是乘上2 ^ (x - 1),每个数字的贡献都是2 ^ (x - 1) 总贡献就是2 ^ (N - ∑(vis[i])).大数可以一边读入一边取模. 1 #include <bits/s

ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)

https://nanti.jisuanke.com/t/30996 题意 每天增加m个灯泡,n个房间,能一次性换就换,模拟换灯泡过程.询问第几天的状态 分析 离线做,按题意模拟.比赛时线段树写挫了..导致不断超时,我太弱了.每次询问符合要求的最左边的点. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <string> #i