杭电2015'11校赛

账号:team1711 

密码:189225

1001 搬砖

Problem Description
  小明现在是人见人爱,花见花开的高富帅,整天沉浸在美女环绕的笙歌妙舞当中。但是人们有所不知,春风得意的小明也曾有着一段艰苦的奋斗史。
  那时的小明还没剪去长发,没有信用卡没有她,没有24小时热水的家,可当初的小明是那么快乐,尽管甚至没有一把破木吉他…
  之所以快乐,是因为那时的小明心怀逆袭梦想。有一天,小明为了给他心目中的女神买生日礼物,来到了某建筑工地搬砖挣钱。就在这个时候,工地上又运来了一卡车的砖,包工头让小明把卡车卸下来的那堆砖分成一块一块的(要求任何2块转都要分开)。作为资深搬运工,小明总是每次将一堆砖分为两堆,这时候,所消耗的体力是分完之后两堆砖数目的差值。
  现在,已知卡车运来的砖的数目,请告诉小明最少要花费多少体力才能完成包工头所要求的任务呢?
Input
输入数据第一行是一个正整数T(T<=100),表示有T组测试数据。
接下来T行每行一个正整数N(N<=10000000),表示卡车运来的砖块的数目。
Output
对于每组数据,请输出小明完成任务所需的最少体力数。
Sample Input
  
  
2 4 5
Sample Output
  
  
0 2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1


using namespace std;

int DFS(int n)
{
    if(n == 1)
        return 0;
    if(n & 1)
        return DFS(n/2) + DFS(n/2+1) + 1;
    return DFS(n/2)*2;
}
int main()
{
    int T, N;
    scanf("%d",&T);
    while(T-- && scanf("%d",&N))
    {
        cout<<DFS(N)<<endl;
    }
    return 0;
}

1002投币洗衣机

Problem Description
  如今大学生的生活条件越来越好了,近期,内蒙某高校在每个寝室楼都添置了一台投币洗衣机。
  小明作为经常参加训练的ACM队员,非常忙(Lan)碌(Duo),当然非常乐意把衣服丢给洗衣机解决啦。根据要洗的衣服数量,投币洗衣机每次需要投入2-4 枚硬币。
  小明是一个非常容易出汗的男生,夏天就要到了,每天都要洗澡,所以也就有大量衣服需要洗。
  小明是这么制定投币洗衣机计划的:当屯积的衣服数量大于等于a且小于b的时候,他就会马上全部拿去给洗衣机洗,并且投入2枚硬币;当屯积的衣服数量大于等于b且小于c的时候,他就会马上全部拿去给洗衣机洗,并且投入3枚硬币;当屯积的衣服数量大于等于c的时候,他就会马上全部拿去给洗衣机洗,并且投入4枚硬币。其他细节见样例。
  现在知道,小明过去n 天每天换下的衣服数量v件,需要你帮忙计算出小明在过去这段时间洗衣服一共花了多少钱。
Input
输入包含多组测试数据。
每组数据第一行是4个正整数 n (1<=n<=10000) 、a 、b 、c (1<=a<b<c<=300),具体含义见题目描述。
每组数据第二行包含n个正整数,按顺序表示过去n天每天产生的衣服数量v(1<=v<=1000)。
Output
每组数据输出一个整数,表示小明过去n天中洗衣服一共花了多少钱。
每组输出占一行。
Sample Input
  
  
3 2 4 6 2 2 1
Sample Output
  
  
4
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

int main()
{
    int n, a, b, c, x;
    while(~scanf("%d%d%d%d",&n,&a,&b,&c))
    {
        int sum = 0;
        int up = 0;
        for(int i=0; i<n;i++)
        {
            scanf("%d",&x);
            int t = x + up;
            if(t >= a && t < b)
                sum += 2, up = 0;
            else if(t >= b && t < c)
                sum += 3, up = 0;
            else if(t >= c)
                sum += 4, up = 0;
            else
                up += x;
        }
        cout<<sum<<endl;
    }
    return 0;
}

1003玩骰子


Problem Description
  Nias与Ains都特别喜欢玩骰子,而且都自以为比对方玩得更溜。
  终于有一天,他们决定用骰子来一决高下!
  一般的骰子玩法已经不足以体现他们的水平了,于是他们自创了一套玩法来PK:
首先,每人掷3个骰子;之后,可以选择其中一个骰子重新掷(当然也可以放弃这一步),最后,比较投掷结果的大小,结果大的那方获胜,一样的话为平局。
  大小比较规则为:
  三个一样数字的骰子称为三条;两个一样数字的骰子称为对子;只有一个数字的骰子成为散牌。三条>对子>散牌。当双方结果都为三条时,直接比较三条数字的大小;都有对子时,先比较对子数字的大小,若相同,再比较剩下的骰子的数字的大小;都只有散牌时,先比较最大的数字的大小,若相同,再比较次大的数字的大小,还相同,最后比较最小的数字的大小。
  现在Nias已经投了3个骰子,还剩一次机会可以选择其中一个骰子重新投(或不选),而且他已经知道了Ains的最后投掷结果,求Nias获胜的概率有多大。
Input
输入数据第一行为一个整数T,表示有T组测试数据。
接下来T行,每行6个1~6的整数,前三个表示Nias第一次的投掷结果,后三个表示Aias最终的投掷结果。
Output
请输出Nias获胜的概率,结果保留3位小数,每组输出占一行。
Sample Input
  
  
4 2 3 5 3 3 4 3 3 1 2 2 2 6 2 1 5 4 3 1 2 3 4 4 1
Sample Output
  
  
0.333 0.167 1.000 0.000

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;
int A[10];
int judge(int a,int b,int c)
{
    int x;
    if(a==b&&b==c)
        x=a*A[9];
    else if(a==b||a==c||b==c)
    {
        if(a==b)
            x=a*A[8]+A[c];
        else if(b==c)
            x=b*A[8]+A[a];
        else if(a==c)
            x=a*A[8]+A[b];
    }
    else
        x=A[a]+A[b]+A[c];
    return x;
}
int main()
{
    A[1]=1;
    for(int i=2; i<10; i++)
        A[i]=A[i-1]*10;
    int a,b,c,t,x,y,z,g;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d%d%d",&a,&b,&c,&x,&y,&z);
        g=judge(x,y,z);
        if(judge(a,b,c)>g)
        {
            printf("1.000\n");
            continue;
        }
        int cnt;
        int p=0;
        for(int i=1; i<=3; i++)
        {
            cnt=0;
            for(int j=1; j<=6; j++)
            {
                if(i==1)
                {
                    if(judge(j,b,c)>g)
                        cnt++;
                }
                else if(i==2)
                {
                    if(judge(a,j,c)>g)
                        cnt++;
                }
                else
                {
                    if(judge(a,b,j)>g)
                        cnt++;
                }
            }
            p=max(p,cnt);
        }
        printf("%.3lf\n",p/6.0);
    }
    return 0;
}

1004质方数

Problem Description
  小明天生对数字比较敏感,3岁的时候就能背诵圆周率一百位。
  现在,小明慢慢长大了,但依然很喜欢数字,最近,他迷上了质数和平方数,并且自己把质数的平方命名为“质方数”。
  现在,他在研究这样一个问题:距离一个正整数N最接近的质方数是多少?
Input
输入数据第一行是一个正整数T(T<=20),表示有T组输入数据。
接下来T行,每行输入一个正整数N(1<=N<=10^8)。
Output
对于每组数据,请输出距离N最接近的质方数,每组输出占一行。
Sample Input
  
  
2 1 10
Sample Output
  
  
4 9

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn = 10100;
int Prim[maxn];
bool isPrim[maxn];
int Prim_num;

void PrimTable()
{
    memset(isPrim, false, sizeof(isPrim));
    Prim_num = 0;
    Prim[Prim_num++] = 2;
    for(int i = 3; i <= maxn; i += 2)
    {
        if(!isPrim[i])
        {
            Prim[Prim_num++] = i;
            for(int j = i*i; j <= maxn; j += i)
                isPrim[j] = true;
        }
    }
}


int main()
{
    PrimTable();
    int N;
    int T;
    scanf("%d",&T);
    while(T-- &&scanf("%d",&N))
    {
        int MAX = INF;
        int pos;
        for(int i = 0; i < Prim_num; i++)
        {
            LL P = fabs(Prim[i] * Prim[i] - N);
            if(MAX > P)
            {
                pos = i;
                MAX = P;
            }
        }
        cout<<Prim[pos]*Prim[pos]<<endl;
    }
    return 0;
}

1005ACM组队安排

Problem Description
  ACM亚洲区比赛结束,意味着开始备战明年的浙江省大学生程序设计竞赛了!
  杭州电子科技大学ACM集训队也准备开始组队。
  教练想把所有的n个队员组成若干支队伍,原则是每支队伍至少一人,最多三人。
  现在问题来了:如果已知集训队队员的数量n,请你帮教练计算出所有可能的组队方案有多少种。
  特别说明:
  队伍没有编号,即如果有A,B,C三人,{A}{BC}与{BC}{A}是同一种组队情况。
Input
输入包含多组测试数据(约1000组),每组数据占一行,包含一个数字n(0<=n<=20),表示ACM集训队的队员人数;n为0,表示输入结束。
Output
请输出n个队员所有可能的组队方案数,每组输出占一行。
Sample Input
  
  
1 2 3 4 5 0
Sample Output
  
  
1 2 5 14 46
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

int c[22][22];
void Init()
{
    for(int i=0; i<22; i++)
    {
        for(int j=0; j<=i; j++)
        {
            if(j==0 || i == j)
                c[i][j] = 1;
            else
                c[i][j] = c[i-1][j] + c[i-1][j-1];
        }
    }
}

int main()
{
    Init();
    LL A[22] = {0,1,2,5};
    for(int i=4; i<=20;i++)
        A[i] = A[i-1] + c[i-1][1]*A[i-2] + c[i-1][2]*A[i-3];
    int N;
    while(cin>>N && N)
        cout<<A[N]<<endl;
    return 0;
}

1006逆袭指数

Problem Description
  这依然是关于高富帅小明曾经的故事——
  尽管身处逆境,但小明一直没有放弃努力,除了搬砖,小明还研究过东方的八卦以及西方的星座,一直试图在命理上找到自己能够逆袭的依据。
  当这些都失败以后,小明转向了数学研究,希望从中得到一些信息。一天,小明在研究《BestCoder逆袭的数理基础》这本书时,发现了宝贵的信息,其中写道:
  每个人都存在一个逆袭指数,对于这个逆袭指数,可能存在连续的因子,如果这个连续因子足够长的话,那么这个人逆袭的概率就很大!
  小明已知自己的逆袭指数,请告诉小明他最长的连续因子,以让他来判断他自己是否能够逆袭。
Input
输入包含多组测试数据。
每组数据占一行,包含一个整数N,表示小明的逆袭指数,N小于2^31。
Output
对于每组数据,请输出2行:
第一行输出最长的因子个数;
第二行输出最小的因子序列,具体请参考样例。
特别说明:由于小明十分讨厌单身,所以1不算因子。
Sample Input
  
  
630 12
Sample Output
 
 
3 5*6*7 2 2*3
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

int MAX;
int a[1010],b[1010];
void DFS(int n,int i,int len)
{
    if(len  >  MAX)
    {
        MAX = len;
        for(int i=0; i<MAX; i++)
            a[i] = b[i];
    }
    if(n % i == 0 && n != 1)
    {
        b[len] = i;
        DFS(n/i,i+1,len+1);
    }
}
int main()
{
    int N;
    while(~scanf("%d",&N))
    {
        MAX = 0;
        for(int i=2; i*i <= N; i++)
            DFS(N,i,0);
        if(MAX == 0)
            MAX = 1, a[0] = N;
        printf("%d\n",MAX);
        for(int i=0; i<MAX; i++)
        {
            if(!i)
                printf("%d",a[i]);
            else
                printf("*%d",a[i]);
        }
        printf("\n");
    }
    return 0;
}


1007油菜花王国

Problem Description
  程序设计竞赛即将到来,作为学校ACM集训队主力,小明训练一直很努力。今天天气不错,教练也心情大好,破例给各位队员放假一天,小明就骑着自己的小电驴到郊外踏青去了。
  出城不久,小明看到一大片油菜花,忍不住眼前美景的诱惑,就拐了进去,谁曾想,这一拐却误入了油菜花王国!
  油菜花王国生存着一大批油菜花精灵,这是一种特别热爱斐波那契数列的生物。在这个国度里,有若干个家族,每只精灵都只属于一个家族。精灵出生时,身上都会印着一个编码,表示这只精灵的能力值,如果这个能力值正好存在于斐波那契数列,那么他就会为所在的家族增加一点威望。小明通过和精灵们聊天,知道了所有精灵之间的关系。
  现在,小明想知道油菜花王国里威望值最大的家族的威望值是多少,你能帮帮他吗?小明会把精灵们之间的关系网络告诉你,由于整个关系网络实在太庞大,所以小明很有可能重复介绍其中一些关系。
 
Input
输入包含多组数据。
每组数据第一行包含两个整数 n (1 <= n <= 1000) 、 m (1 <= m <= 5000) ,分别表示油菜花王国精灵数量和精灵之间关系组数。
第二行包含 n 个整数,表示精灵们的能力值 k (1 <= k <= 1000000000)。
接下去有 m 行,每行有两个不同的整数 u 、 v (1 <= u, v <= n) ,表示精灵 u 和精灵 v 属于同一个家族。
Output
请输出威望值最大的家族的威望值,每组数据对应一行输出。
 
Sample Input
  
  
2 1 1 4 1 2
 
Sample Output
  
  
1

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

const int maxn =  1000000000;
LL k[1010];
LL a[1010];
int b[1010];
int F[1010];
int Find(int x)
{
    return  x== F[x] ? x : F[x] = Find(F[x]);
}
void Link(int u,int v)
{
    int f1 = Find(u);
    int f2 = Find(v);
    if(f1 != f2)
        F[f1] = f2;
}
void Init()
{
    a[1] = a[2] = 1;
    for(int i=3; i<=50; i++)
        a[i] = a[i-1] + a[i-2];
}
int main()
{
    Init();
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1; i<=n; i++)
        {
            cin>>k[i];
            F[i] = i;
        }
        for(int i=0; i<m; i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            Link(u,v);
        }
        memset(b,0,sizeof(b));
        int MAX = 0;
        for(int i=1; i<=n; i++)
        {
            int pos = Find(i);
            for(int j=1; j<=50; j++)
            {
                if(k[i] == a[j])
                {
                    b[pos]++;
                    break;
                }
                if(a[j] > k[i])
                    break;
            }
            MAX = max(MAX,b[pos]);
        }
        printf("%d\n",MAX);
    }
    return 0;
}


1008游乐场

Problem Description
  小时候,因为家里经济困难,小明从未去过游乐场,所以直到现在,他还心存遗憾。
  最近,杭州刚建了一座游乐场,为了弥补儿时的遗憾,小明带了一笔钱迫不及待地要去体验一番。
  由于是第一次来到这种地方,小明也不知哪些项目比较好玩,因此他想体验尽可能多的项目。来之前,小明还向朋友打听了一下关于游乐场的情况,只要是朋友推荐过的,他一定要体验。当然,每个项目都需要一定的花费,当小明的钱不够时就不能再玩了。

  现在,已知小明身上的钱以及每个游戏项目的花费,请问小明最多能体验多少个项目?
 
Input
输入第一行为一个整数T,表示有T组测试数据。

对于每组数据:
第一行是三个整数n, m, k,分别表示游乐场里的游戏项目数,朋友推荐的游戏项目数,小明身上的钱数(1<=m<=n<=10000, 1<=k<=10^9)。
第二行是n个整数,第i个整数xi表示第i个游戏项目的费用(1<=xi<=10^9)。
第三行是m个整数pi,表示朋友推荐第pi个游戏项目(1<=pi<=n)。
 
Output
如果小明带的钱连朋友推荐的项目都无法全部体验,请输出-1;否则,请输出小明最多能体验的项目数。

每组输出占一行。
 
Sample Input
   
   
2 5 2 10 4 3 8 1 12 1 2 5 2 10 4 3 8 1 12 1 3
 
Sample Output
   
   
3 -1
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1

using namespace std;

struct node
{
    LL data;
    int id;
    int val;
} a[10010],b[10010];

bool cmp(node x,node y)
{
    return x.data < y.data;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,m;
        LL k;
        scanf("%d%d%lld",&n,&m,&k);
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i].data);
            a[i].val = 0;
        }
        LL sum = 0;
        for(int i=0; i<m; i++)
        {
            int x;
            scanf("%d",&x);
            a[x-1].val = 1;
            sum += a[x - 1].data;
        }
        if(sum > k)
            printf("-1\n");
        else
        {
            sort(a,a+n,cmp);
            int ant = m;
            k -= sum;
            for(int i=0; i<n; i++)
            {
                if(a[i].val == 0)
                {
                    k -= a[i].data;
                    if(k >= 0)
                        ant++;
                    else break;
                }
            }
            printf("%d\n",ant);
        }
    }
    return 0;
}




  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值