GCJ Round 1C 2016 题解

  • ASenate Evacuation
  • B Slides
  • C Fashion Police

A.Senate Evacuation

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
int n,a[100];
int check() {
    int p=0;
    Rep(i,n) p=max(p,a[i]);
    return p;
}
int main()
{
    freopen("A.in","r",stdin);
    freopen("a.out","w",stdout);

    int T=read();
    For(kcase,T) {
        printf("Case #%d: ",kcase);
        cin>>n;
        int t=0;
        Rep(i,n) cin>>a[i],t+=a[i];
        while(t) {
            int p=0;
            For(i,n-1) if (a[p]<a[i]) p=i;
            a[p]--;
            --t;
            if (check()*2>t) {
                putchar(p+‘A‘);
            }
            else {
                putchar(p+‘A‘);
                if (t) putchar(‘ ‘);
            }
        }
        puts("");
    }

    return 0;
}

B. Slides!

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch==‘-‘) f=-1; ch=getchar();}
    while(isdigit(ch)) { x=x*10+ch-‘0‘; ch=getchar();}
    return x*f;
}
ll m, n;
int b[100][100];
ll f[56];
void go(int l,int r){
    Fork(i,l,r)
        Fork(j,i+1,r)
            b[i][j]=1;
    Fork(i,l,r) b[i][n]=1;
}
int p2[55];
int c[100][100];
int main()
{
    freopen("B.in","r",stdin);
    freopen("b.out","w",stdout);

    f[0]=0;
    f[1]=f[2]=1;
    Fork(i,3,50) f[i]=f[i-1]*2LL;

    p2[0]=1;
    For(i,50) p2[i]=p2[i-1]*2ll;

    int T=read();
    For(kcase,T) {
        printf("Case #%d: ",kcase);
        cin>>n>>m;

        if (m>f[n]) {puts("IMPOSSIBLE");
            continue;
        }
        puts("POSSIBLE");

        MEM(b)
        go(2,n);
        ll t=f[n];
        Fork(i,2,n){
            if (t-f[n-i+1]>=m) {
                t-=f[n-i+1];
            }else b[1][i]=1;
            if (!t) break;
        }

        For(i,n) Fork(j,i,n) b[j][i]=0;
        memcpy(c,b,sizeof(b));
        For(k,n)
            For(i,n) For(j,n)
                c[i][j]=c[i][j]+c[i][k]*c[k][j];

        For(i,n){
            For(j,n) if (b[i][j]&&i<j) putchar(‘1‘); else putchar(‘0‘);puts("");
        }
//      cout<<c[1][n]<<endl;

    }

    return 0;
}

C. Fashion Police

时间: 2024-10-14 02:03:15

GCJ Round 1C 2016 题解的相关文章

TCO 2014 Round 1C 概率DP

TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover,肯定就是dp[l][r][n], 走了n步之后,左边cover了l,右边cover了r. 一开始DP没有搞清楚,这个要画一下图就更清楚了. 转移方程就是概率的传递方向. 1: double dp[505][505][2]; // l,r,n steps unsed; 2: class RedPain

Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)

Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a window separates adjacent cells, and

POJ 3252 Round Numbers 数学题解

Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets

PA 2011 Round 3 prz题解

题目大意,现在要走过一条斑马线,斑马线是由n条交替的黑条和白条构成的,第一条是黑条.脚的长度是s.要求在走的过程中,他脚的任何一部分都不能碰到象征邪恶的黑条.第一条之前和第n条之后的部分都是白色的,可以任意选择第一条之前的位置出发.但出发位置一旦选定,之后每一步的长度都必须是k.请你判断有没有可能在不碰到黑条的情况下通过斑马线,即走到第n条之后. 此题同样是模拟赛题!!! 我现在已经非常质疑自己的智商了,为什么每次都是离正解只差一步呢,每次都不能换一个思路去想一想. 先说说我的错误解法:我列了n

Educational Codeforces Round 64部分题解

Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点个数是否有限,如果有限,输出. 很明显当正方形套三角形或者三角形套正方形是交点个数是无限的(因为有一条边相交) 其他图形的嵌套交点个数比较好判断,不多赘述 但是注意坑点: 当按照矩形,园,三角这样的顺序是,三角与圆的一个交点是与圆和正方形的交点重合的,判一下就好了 #include<cstdio>

GCJ 2015 Round 1C B. Typewriter Monkey

用最多需要的香蕉数减去目标串出现的概率就行啦.... 如何求出现的概率? 每个字符出现的概率乘起来--再乘以目标串能摆的位置个数-- Problem Your publishing house has decided to use monkeys randomly typing at keyboards to write great works of literature. You are the supervisor for one monkey with a keyboard contain

GCJ 2015 Round 1C C. Less Money, More Problems

如果现在能够组成1...x 的面值,加上一种 x+1 面值的纸币,就能组成 1 ... x + C * (x + 1)的面值. 因为如果面值是 k < (C+1)*(x + 1),我们可以用 k / (x + 1) 张 x+1 面值的纸币,并用原来的纸币组成 k % (x + 1),就得到了 k . 每次添加不能被表示的最小面值的纸币是最优的. Problem Up until today, the nation you live in has used D different positive

Google Code Jam 2016 Round 1C C

题意:三种物品分别有a b c个(a<=b<=c),现在每种物品各选一个进行组合.要求每种最和最多出现一次.且要求任意两个物品的组合在所有三个物品组合中的出现总次数不能超过n. 要求给出一个方案,使得我们能够生成的组合数最多. 分析: 首先我们可以简单的处理一种情况,就是c<=n的情况. 因为我们枚举出了所有组合,那么两物品的出现次数的最大值不会超过c,因为A种和B种的每对组合都会在其中出现c次,其余两个的组合出现次数更少. 所以这种情况一定不会超过n,我们只需要枚举所有组合即可. 然而

GCJ 2009 Round 1C Bribe the Prisoners

Bribe the Prisoners no tags     Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. Cells number i and i+1 are adjacent, and prisoners in adjacent cells are called "neighbours." A wall with a wind