2017浙江理工校赛 A、D、I 待补完

可做题很多,这几天补完!

Problem A: 回文

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 1672   Solved: 517

Description

小王想知道一个字符串是否为 ABA’ 型字符串。 ABA’ 型字符串的定义: S=ABA’ A B A’ 都是原字符串的子串 ( 不能是空串), A’ 的意思是 A 的反转串, B 不一定要和 A A’ 不同。符合 ABA’ 型的例如: "aba” "acbbca” "abcefgcba” 等。 "Abcefgcba” ABA’ 型,因为它能找到一组对应的 A "abc”) B(”efg”) A’("cba") 满足定义。

Input

第一行给测试总数 T(T <= 1000) ,接下来有 T 组测试数据。
每组测试数据有一行字符串 S(1 <= |S| <= 50000) ,字符串保证只有小写或大写英文字母。

Output

每组测试数据输出一行,如果 S ABA’ 型字符串,输出 "YES” ,否则输出 "NO"

Sample Input

5
abA
gg
Codeforces
acmermca
myacm

Sample Output

NO
NO
NO
YES
YES
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 50010;
char s[maxn];
int main(){
    int t,i,j;
    scanf("%d",&t);
    while(t--){
        scanf("%s",s);
        getchar();
        int len = strlen(s),lef,rig;
        if(len==1){
            printf("NO\n");
            continue;
        }
        lef = 0,rig = len-1;
        bool flag = false;
        if(s[lef]==s[rig]&&len>2){
            flag = true;
        }
        if(flag){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

Problem I: 约素

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1844  Solved: 480

Description

判断一个正整数n的约数个数是否为p,其中p是素数。

Input

第一行给测试总数T(T <= 10000)。

接下来有T行,每行有两个数字n(1 <= n <= 1000000000)和p(2 < p <= 1000000000)。

Output

每组测试数据输出一行,如果n的约数个数是p,输出“YES”,否则输出“NO”。

Sample Input

564 7911 2331080 131024 1120170211 1913

Sample Output

YESNONOYESNO
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
const int maxn = 1e6+10;
long long vis[maxn];
long long prime[maxn];
long long p_n=0;
void init(){
    p_n=0;
    long long i,j;
    memset(vis, 0, sizeof(vis));
    for(i=2;i<=maxn;i++){
        if(!vis[i]){
            prime[p_n++] = i;
            for(j=i*i;j<=maxn;j+=i){
                vis[j]=1;
            }
        }
    }
}
int main(){
    int t;
    long long n,p,i,j;
    init();
    prime[0] = 2;
    scanf("%d",&t);
    while(t--){
        scanf("%lld%lld",&n,&p);
        bool flag = false;
        long long limi = sqrt(n);
        for(i=0;prime[i]<=limi&&i<p_n;i++){
            long long now = 1;
            for(j=1;now<=n;j++){
                now *= prime[i];
                if(now == n&&p==j+1){
                    flag = true;
                    goto here;
                }
            }
        }
    here:
        if(flag){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

Problem D: 买iphone

Time Limit: 3 Sec   Memory Limit: 128 MB
Submit: 1818   Solved: 339

Description

自从上次仓鼠中了1000万彩票后,彻底变成了土豪了,一群人愿意认他做干爹,仓鼠决定送他的干儿子每人一部iphone。仓鼠今天带了一群人去买iphone,每个人身上都背着一个大背包,只有3种背包,分别能装a,b,c个iphone,仓鼠希望每个人都能用iphone装满自己的背包。仓鼠有n个干儿子,也就是要买n部手机,仓鼠带了k个人去买手机,问是否存在一种情况能让每个买iphone的人的背包都装满

Input

输入包含多组测试数据,每组一行,包含5个整数n, k, a, b, c
(1 <= n, k , a, b, c <= 10000)
abc可以相同

Output

如果存在输出Yes,否则输出No

Sample Input

10 3 3 3 4
20 7 1 1 1
80 3 100 3 3
15 4 3 5 6

Sample Output

Yes
No
No
Yes

HINT

样例一3个人分别带大小为 3 3 4的背包去买手机正好每个人都装满

样例二 很明显只有一种背包,全部都是1也无法买20部iphone

样例四 4个人分别带大小为 3 3 3 6的背包去买手机正好每个人都装满

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int i;
    int n,k,a,b,c;
    while(~scanf("%d%d%d%d%d",&n,&k,&a,&b,&c)){
        bool flag = false;
        int y1,y2;
        int x3,x2;
        for(i=0;i<=10000;i++){
            y1 = k-i;
            y2 = n-a*i;
            if(y1<0||y2<0){
                continue;
            }
            if(b==c){
                if(y2%b==0){
                    if(y2/b==y1){
                        flag = true;
                        break;
                    }
                }
                continue;
            }
            if((b*y1-y2)%(b-c)==0){
                x3 =(b*y1-y2)/(b-c);
                if(x3>=0){
                    x2 = y1 - x3;
                    if(x2>=0){
                        flag = true;
                        break;
                    }
                }
            }
        }
             
        if(flag){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值