2017年浙江中医药大学大学生程序设计竞赛(重现赛)

A题是真的难  很艰难的不会;

B 一生之敌

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

大家都知道Alice和Bob两个人是一生之敌。(雾  
但某天,他们两个人发了疯。想知道他们两个是否可以成为朋友。  
于是他们做了一个令人窒息的决定。    
Alice和Bob每个人任意选一个整数。  
假设Alice选择了整数a,Bob选择了整数b。  
Alice使得a做如下变换:  
a -> 2 * a * (a+1)^2
Bob使得b做如下变换:  
b -> b^2
如果变换后的数字相等,则两个人可以化敌为友。  
如果不相等,这两个人怕是石乐志。
现在,你想把Bob部分可能的整数b(存在a变换后的数字等于b变换后的数字)从小到大排列后,知道第一个大于等于n的数字是多少。


输入描述:

第一行输入一个整数T,表示数据组数。
每组数据输入一个整数n。
1 <= T <= 100000
0 <= n <= 10^19
保证结果存在

输出描述:

输出一个整数。
示例1

输入

3  
2  
6  
100

输出

6
6
114
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<cstdlib>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
typedef unsigned long long LL;

const LL maxn=3e6+7;
unsigned long long n,a[maxn];

int main ()
{
    for(LL i=0;i<=maxn;i++)
        a[i]=4*i*i*i+2*i;
    int t;
    cin>>t;
    while(t--)
    {
        scanf("%llu",&n);
        LL ans=lower_bound(a,a+maxn,n)-a;//有序后,返回第一个大于或者等于n的下标
        printf("%llu\n",a[ans]);
    }
    return 0;
}
C题:一个贪心的东西,向中间靠齐;
C 寻找zcmu
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

一年一度的浙江中医药大学程序设计校赛正在火热进行,举办至今这是第十一届校赛了。
那么今年就来寻找一下zcmu。
这里有一串只包含小写字母的字符串,里面有若干个zcmu,你为了省力,需要知道最少需要删除几个字符是的有连续四个字符是"zcmu"。

输入描述:

多组数据
每组数据包含一个字符串
1 <= n <= 100000

输出描述:

输出一个整数表示最少需要删除的字符数,若不存在则输出"-1"。
示例1

输入

zcmu
umcz
zzccmmuuaa

输出

0
-1
2
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;

const int maxn=1e6+7;
char str[maxn];

int main ()
{
    while(~scanf("%s",str))
    {
        int len=strlen(str);
        int z=-1,c=-1,m=-1,u=-1,Min=-1;
        for(int i=0;i<len;i++)
        {
            if(str[i]=='z') z=i;
            else if(str[i]=='c'&&z!=-1) c=z;
            else if(str[i]=='m'&&c!=-1) m=c;
            else if(str[i]=='u'&&m!=-1)
                if(Min==-1||Min>i-m-3) Min=i-m-3;
        }
        printf("%d\n",Min);
    }
    return 0;
}
D:很弱鸡的一个pa
D CC的神奇背包
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

cc最近收到了好多礼物,对着满地大小不一的礼物,她想要一个包来装,于是dd就掏出了一个会说话的神奇背包给cc装礼物。
cc为了一次性装尽可能多的礼物,于是跟这个背包定下了一个规则,对每个礼物,背包会给出它对这件礼物的喜爱程度,背包越喜欢这个礼物,它就会越开心,越开心,它就会扩大自己的容量。
于是问题就变成了这样:每个礼物都有自己的体积ai,背包也会给出它对这些礼物的喜爱程度bi,并且为了方便cc计算,背包告诉cc,喜爱程度bi就是这件物体放进背包,背包后会扩大的体积。
那么现在cc想知道,对这一地的礼物,有没有某种放的顺序,可以一次性把所有礼物都放进包里?
当然,物体要先放进背包,背包才会扩大自己的体积
比如当前背包的剩余体积为2,礼物的体积为3,喜爱程度为4,也是不能放进背包的。

输入描述:

输入包含多组数据,第一行为一个整数T(1<=T<=20)
每组数据第一行包含两个整数n,v(1<=n,v<=1000)表示共有n个礼物,背包一开始的体积为v
接下去的n行每行包含两个整数ai,bi(1<=ai,bi<=1000)表示每个礼物的体积ai与背包对这件礼物的喜爱程度bi
1 <= T <= 20
1 <= n, v <= 100000
1 <= ai, bi <= 100000

输出描述:

若存在一种放礼物的顺序可以让cc把所有礼物放进背包,则输出"yes"否则输出"no"(引号不包含在内)
示例1

输入

1
4 2
1 2
2 1
3 1
2 3

输出

yes
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;

const int maxn=1e6+7;
int  n,t,v;
struct node
{
  int a,b;
}num[maxn];

bool cmp(node a,node b)
{
    return a.a<b.a;
}

void solve()
{
    LL cnt=v;
    for(int i=0;i<n;i++)
    {
        if(num[i].a>cnt||cnt<0) {puts("no");return ;}
        else cnt+=(num[i].b-num[i].a);
    }
    puts("yes");
}

int main ()
{
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%d %d",&n,&v);
            for(int i=0;i<n;i++)
                scanf("%d %d",&num[i].a,&num[i].b);
            sort(num,num+n,cmp);
            solve();
        }

    }
    return 0;
}
E:签到题;
EPizza
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

一天dd很开心的送给cc一块Pizza当午饭,虽然大家都不觉得cc胖,但作为一个女孩子,觉得自己胖是每个女孩子都有的错觉...当然cc也不想辜负dd的一片好心,所以她决定把这块Pizza分成等质量的很多块然后跟dd一起分享,显然cc只打算吃一块,剩下的都给dd吃。而一块质量为x的Pizza会使cc获得k*x的卡路里(k为常数)。
在吃Pizza前,cc想知道自己会获得多少卡路里。

输入描述:

多组数据,第一行读取一个整数T(1<=T<=20000)
接下去的每行包含两个整数n,k表示Pizza的质量和常数k(1<=n,k<=2147483648)

输出描述:

输出cc最少会获得的卡路里
示例1

输入

1
1 2

输出

2
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;

int main ()
{
    LL n,m;
    int t;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%lld %lld",&n,&m);
            printf("%lld\n",m);
        }
    }
    return 0;
}
F:不开心与kaixin
F开心的cc
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

CC is a smart girl and she is curious about everything. One day she starts to analyze her lifestyle and finds out that she either feels happy or unhappy in any day, then she collects her mood data and makes numerical representation. She writes down 1 if she is happy, otherwise she writes down 0. 
For example, if CC is happy, happy, unhappy, happy, happy, unhappy in the next 6 days, a numerical sequence which stands for it is 1,1,0,1,1,0

Meanwhile, smart CC finds her mood sequence is always periodic. She also finds the repeated segment like 1,1,0 in the aforementioned example and calls it “feeling repetend”. As a curious girl, CC wants to make another deep analysis. After she gets the length of “feeling repetend” n, she defines a rule: she tries to find a day whose index is d and considers the next d+n-1 days. For each day d' in [d, d+n-1], CC guarantee that the number of happy days is more than unhappy days in [1, d'] days.

Now, CC wonder that how many days which satisfy the rule in n “feeling repetend” days.

输入描述:

Input contains multiple test cases.
The first line contains an integer T (1<=T<=20), which is the number of test cases.
Then the first line of each test case contains an integer n (1<=n<=100000), which is the length of “feeling repetend”.
The second line of each test case contains n integers, each integer is either 0 or 1, standing for unhappy or happy.

输出描述:

output a integer represents the answer.
示例1

输入

2
5
1 0 1 1 0
5 
1 1 1 1 1

输出

1
5

说明

For the sample,the days from the third day as a starting point are as follows:
Day1: 1 day happy : 0 days unhappy
Day2: 2 days happy : 0 days unhappy
Day3: 2 days happy : 1 day unhappy
Day4: 3 days happy : 1 day unhappy
Day5: 3 days happy : 2 days unhappy
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;

const int maxn=1e6+7;
char str[maxn];

int main ()
{
    int t;
    scanf("%d",&t);
        int key;
        while(t--)
        {
            int n,x=0,y=0;
            scanf("%d",&n);
            while(n--)
            {
                scanf("%d",&key);
                if(key==1) x++;
                else y++;
            }
            if(x>y) cout<<x-y<<endl;
            else cout<<"0"<<endl;
        }
    return 0;
}
G:签到
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 131072K,其他语言262144K
64bit IO Format: %lld

题目描述

dd是ACM校队的队员之一,云南的比赛他们队开心的获得了来回都是飞机的机会。机智的dd想带好多特产回来,所以在去的时候行李箱里什么都没放,本着空箱子去,满箱子回的心态去了云南。
众所周知,在上飞机办理托运的时候,行李箱的重量会显示出来,细心的cc默默记下了dd去的时候托运的重量N,和回来的时候托运的重量M,这样她就可以知道dd到底带了多少特产回来了~


输入描述:

多组数据,第一行包含一个整数T(T<=10000)表示共有T组数据
之后每行读取三个实数N,M(1<=N,M<=2147483648)

输出描述:

输出一个整数表示dd带回来的特产重量
示例1

输入

2
3 6
1 3

输出

3
2
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
typedef long long LL;

int main ()
{
    LL n,m;
    int t;
    while(~scanf("%d",&t))
    {
        while(t--)
        {
            scanf("%lld %lld",&n,&m);
            printf("%lld\n",m-n);
        }
    }
    return 0;
}

由于本人比较弱鸡 所以~~~以后再补题解吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值