2016中国大学生程序设计竞赛 - 网络选拔赛【三水题 1001 && 1004 && 1011】

本文提供了2016年中国大学生程序设计竞赛中三道题目的详细解答过程,包括大数取余解决整除问题、礼物分配的最大化策略及字符串中最长严格递增子序列的计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2016中国大学生程序设计竞赛 - 网络选拔赛【三水题】


Problem 1001 A water problem


题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5832

题意:数能否被137和73整数

解题:大数取余

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;
const int maxn = 10001000;
int n;
char s[maxn];
int main(){
    int t = 1;
    while(~scanf("%s",s)){
        printf("Case #%d: ",t++);
        int len = strlen(s);
        int ans1 = 0;
        int ans2 = 0;
        for(int i=0;i<len;i++){
            ans1 = (int)((LL) ans1*10+s[i]-'0') % 73;
            ans2 = (int)((LL) ans2*10+s[i]-'0') % 137;              
        }
        if(ans1==0 && ans2==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }

    }
    return 0;
}

Problem 1004 Danganronpa


题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5835

题意: n种礼物,其量为a[i],要求小朋友收到一神秘礼物和一普通礼物,相邻两个小朋友不能收到相同种类的普通礼物,神秘礼物没限制,问最多收到礼物的小朋友人数。

题解:题目数据有点水,卡了n久,不考虑神秘礼物,就算最多有多少个小朋友可以拿到两件礼物。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;
#define eps 1e-6
#define pi 3.14159265359
typedef long long LL;
typedef long double LD;
const int maxn = 100100;
int t,n,k;
int a[maxn];
int main(){
    scanf("%d",&t);
    for(int k=1;k<=t;k++){
        scanf("%d",&n);
        a[0] = 0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            a[0] += a[i];
        }
        if(a[0]==1)printf("Case #%d: %d\n",k,1);
        else printf("Case #%d: %d\n",k,a[0]/2);
    }
    return 0;
}

Problem 1011 Lweb and String


题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5842

题目:求串的最长 严格递增 子序列的长度

题解:傻逼了我,求不同字母的个数

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define eps 1e-6
#define pi 3.14159265359
typedef long long LL;
const int maxn = 100100;
int n,m,k,t;
char s[maxn];
int main(){

    scanf("%d",&t);
    for(int k=1;k<=t;k++){
        set<char>x;
        scanf("%s",s); 
        n = strlen(s); 
        for(int i=0;i<n;i++){
            x.insert(s[i]);
        }
        printf("Case #%d: %d\n",k,x.size());
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值