Problem Description


You may already know that how the World Finals slots are distributed in EC sub-region. But you still need to keep reading the problem in case some rules are different.

There are totally G slots for EC sub-region. X slots will be distributed among five China regional sites and Y slots will be distributed to the EC-Final. Of course X and Y are non-negative integers and X + Y = G.

Here is how the X slots be distributed:

  1. Slots are assigned to the Asia Regional sites from the first place, the second place, · · · , last place.
  2. For schools having the same place across the sites, the slots will be given in the order of the number of “effective teams” in the sites.
  3. No school could be assigned a slot 2 times, which means the schools will be skipped if they already got a slot.

After X slots are distributed, the EC-Final ranklist from highest rank will be assigned Y slots for those schools that haven’t got a slot yet.

Now here comes a sad story, as X and Y are not announced until the end of the last regional contest of that year, even later!!!

Teachers from a school are worried about the whether they can advance to WF whatever the X and Y is. Let’s help them find out the results before the announcement of X and Y .

Input


The first line of the input gives the number of test cases, T. T test cases follow.

Each test case starts with a line consisting of 1 integer and 1 string, G representing the sum of X and Y and S representing the name of the worried school.

Next 5 lines each consists of 20 string representing the names of top 20 schools in each site. The sites are given in the order of the number of “effective teams” which means the first site has the largest number of “effective teams” and the last site has the smallest numebr of “effective teams”.

The last line consists of 20 strings representing the names of top 20 schools in EC-Final site. No school can appear more than once in each ranklist

Output


For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is “ADVANCED!” if every non-negative value X, Y will advance the school. Otherwise, output the smallest value of Y that makes the school sad.

∙ 1 ≤ T ≤ 200.

∙ School names only consist of upper case characters ‘A’ - ‘Z’ and the length is at most 5.

∙ 1 ≤ G ≤ 20.

Sample Input

1
10 IJU
UIV GEV LJTV UKV QLV TZTV AKOV TKUV
GAV DVIL TDBV ILVTU AKV VTUD IJU IEV
HVDBT YKUV ATUV TDOV
TKUV UIV GEV AKV AKOV GAV DOV TZTV
AVDD IEV LJTV CVQU HVDBT AKVU XIV TDVU
OVEU OVBB KMV OFV
QLV OCV TDVU COV EMVU TEV XIV
VFTUD OVBB OFV DVHC ISCTU VTUD OVEU DTV
HEVU TEOV TDV TDBV CKVU
CVBB IJU QLV LDDLQ TZTV GEV GAV KMV
OFV AVGF TXVTU VFTUD IEV OVEU OKV DVIL
TEV XIV TDVU TKUV
UIV DVIL VFTUD GEV ATUV AKV TZTV QLV
TIV OVEU TKUV UKV IEV OKV CVQU COV
OFOV CVBB TDVU IOV
UIV TKUV CVBB AKV TZTV VFTUD UKV GEV
QLV OVEU OVQU AKOV TDBV ATUV LDDLQ AKVU
GAV SVD TDVU UPOHK

Sample Output

Case #1: 4

Source


2016 CCPC-Final

参考代码

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define inf 1000000000
#define PI acos(-1)
#define REP(i,x,n) for(int i=x;i<=n;i++)
#define DEP(i,n,x) for(int i=n;i>=x;i--)
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void Out(ll a){
if(a<0) putchar('-'),a=-a;
if(a>=10) Out(a/10);
putchar(a%10+'0');
}
const int N=50005;
map<string,int>vis;
string a[6][205],b[25];
int main(){
int T=read();
string c,tmp;
REP(i,1,T){
int G=read();
cin>>c;
REP(i,1,5) REP(j,1,20) cin>>a[i][j];
REP(i,1,20) cin>>b[i];
int ans=inf;
G=min(G,120);
REP(x,0,G){
vis.clear();
int col=1,cnt=x;
REP(i,1,100){
REP(j,1,5){
if(cnt==0) break;
if(vis[a[j][col]]) continue;
vis[a[j][col]]=1;
cnt--;
}
if(cnt==0) break;
col++;
}
cnt=G-x;
REP(i,1,20){
if(cnt==0) break;
if(vis[b[i]]) continue;
vis[b[i]]=1;cnt--;
}
if(!vis[c]) ans=G-x;
}
printf("Case #%d: ",i);
printf(ans==inf?"ADVANCED!\n":"%d\n",ans);
}
return 0;
}

【HDU 6008】Worried School(模拟)的更多相关文章

  1. HDU 6008 - Worried School

    Worried School Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. HDU 5510---Bazinga(指针模拟)

    题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...

  3. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  4. HDU 5965 扫雷 【模拟】 (2016年中国大学生程序设计竞赛(合肥))

    扫雷 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submissi ...

  5. HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))

    Car Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  6. HDU 5912 Fraction 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  7. hdu 4831 Scenic Popularity(模拟)

    pid=4831" style="font-weight:normal">题目链接:hdu 4831 Scenic Popularity 题目大意:略. 解题思路: ...

  8. HDU 5538 House Building(模拟——思维)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5538 Problem Description Have you ever played the vi ...

  9. hdu 4930 斗地主恶心模拟

    http://acm.hdu.edu.cn/showproblem.php?pid=4930 就是两个人玩斗地主,有8种牌型,单张,一对,三张,三带一,三带对,四带二,四炸,王炸.问先手能否一次出完牌 ...

随机推荐

  1. LBP特征

    此篇摘取 <LBP特征原理及代码实现> <LBP特征 学习笔记> 另可参考实现: <LBP特征学习及实现> <LBP特征的实现及LBP+SVM分类> & ...

  2. bzoj 4513 [Sdoi2016]储能表

    题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4513 题解 要求的式子 用数位dp的方法去做 我们把式子拆开 变成 $\sum_{i=0}^ ...

  3. 基于CentOS 7.2个人网盘的实现

    首先使用YUM安装依赖环境: [root@sishen ~]#yum install python python-setuptools python-imaging python-ldap pytho ...

  4. 数位dp知识

    转自http://blog.csdn.net/zhaoxinfan/article/details/8707605 下面先给出数位DP的背景: •在给定区间[A,B]内,找满足要求的数. •要求一般和 ...

  5. 在linux中使用多个redis端口来构建redis集群

    大家好,这是我制作的redis集群搭建视频教程. 服务器:ubnutu server(版本18.10) redis:redis-4.0.12 我这里就简单说明下大概步骤了,详细请观看教学视频. 首先更 ...

  6. [转]浅谈.NET下的多线程和并行计算(二)线程基本知识

    本文转自:http://www.cnblogs.com/lovecindywang/archive/2009/12/25/1632213.html 首先来看看如何创建线程: Console.Write ...

  7. 拦截@RequestBody的请求数据

    要拦截首先想到的是拦截器,@RequestBody只能以流的方式读取,流被读过一次后,就不在存在了,会导致会续无法处理,因此不能直接读流 为了解决这个问题,思路如下: 1.读取流前先把流保存一下 2. ...

  8. 【转】PowerManager 与 WakeLock

    PowerManager 与 WakeLock PowerManager 用来控制设备的电源状态. 而PowerManager.WakeLock 也称作唤醒锁, 是一种保持 CPU 运转防止设备休眠的 ...

  9. 系统设计摘录CAP

    系统架构设计理论与原则 这里主要介绍几种常见的架构设计理论和原则,常见于大中型互联系统架构设计. (一).CAP理论 1.什么是CAP 所谓CAP,即一致性(Consistency).可用性(Avai ...

  10. Android天天数钱游戏项目源码

    Android天天数钱游戏源码,源码功能,天天数钱,这个游戏现在很多线上的小游戏都有这个了,游戏项目是在基于android游戏代码,大家可以参考一下. 源码下载:http://code.662p.co ...