22upc新生训练赛第十五场

13 篇文章 0 订阅

 

问题 D: 彩色旗帜

时间限制: 1.000 Sec  内存限制: 128 MB
提交 状态

题目描述

在小 Q 学校的体艺节上,四、五、六年级各派出了 N 名同学,参加入场仪式。他们按年级分三个纵队站立,每个人手中都高高举起一面旗帜,缓缓走过运动场。彩色的旗帜在微风中伴随着队伍的脚步前进,组成了三条舞动的长龙。如果告诉你队伍中每个人手中彩旗的颜色,你能统计出有多少种颜色是三个队伍中共有的颜色吗? 

输入

第一行有一个整数 N,表示每个队伍中有 N 个人。    
接下来有三行,每行有 N 个正整数 Ki,分别表示三个队伍中各队员手中旗帜的颜色(1 <= N <=10000 , 0<=Ki<=65536。 )。 

输出

输出有多少种颜色是三个队伍中共有的颜色。 

样例输入 Copy

5 
1 3 5 15 6 
6 15 2 3 4 
8  9 6 3 15 

样例输出 Copy

3

提示

【样例解释】 
3 号色,15 号色,6 号色是三个队伍中共同有的颜色。 

这道题还是很坑的 应该是每个队伍里面有相同的 我一开始想试试水 就wa了一次后面还是过了

#include<bits/stdc++.h>
using namespace std;
int k[66000];
map<int,int>mt;
int main()
{
    int n;
    int ans=0;
    cin>>n;
    for(int i=0;i<3;i++){
        for(int j=0;j<n;j++){
            int x;
            cin>>x;
            if(k[x]==0){
                k[x]++;
                mt[x]++;
                if(mt[x]==3)ans++;
            }
        }
        memset(k,0,sizeof k);
    }

    cout<<ans;
    return 0;
}

用一个k数组来判断一下这个队里有没有相同的 

问题 E: 数列

时间限制: 10.000 Sec  内存限制: 128 MB
提交 状态

题目描述

小 Q 被一个数列迷住了。他发现这个数列可以分为连续的 N 段,其中第 i 段是连续 ai个 pi。小 Q 在想有没有快速求数列第 K 项的方法呢?于是他开始不断尝试计算数列第 ki 项的值,但计算量太大,小 Q 想用程序来实现自动计算,你来帮帮他吧。 

输入

第一行有一个整数  N,表示数列分为 N 个重复段。 
接下来有 N 行,每行有两个整数 ai,pi, 表示第 i 段重复了 ai 个 pi。 
第 N+2 行有一个整数  M,表示小 Q 有 M 个查询。 
接下来有 M 个整数 ki,表示小 Q 需要计算数列中第 ki 项的值。 

输出

输出数据有 M 个,每个数依次对应了小 Q 一次查询的结果。 

样例输入 Copy

2 
5 1 
3 2 
3 
1 4 8 

样例输出 Copy

1 1 2 

提示

【样例解释】 
数列有 2 个重复段如下: 
1 1 1 1 1 2 2 2  
小 Q 有 3 个查询,分别查询第 1 项、第 4 项和第 8 项。 
查询结果为:数列中第 1 项的值为 1,第 4 项的值为 1,第 8 项的值为 2。 
【数据范围】 
60%的数据 1 <= N <=1000 , 1<=ai<=1000 , 1<=pi<=1000 ,1<=M<=1000 ,1<=ki<=106。 
100%的数据 1 <= N <=1000 , 1<=ai<=106, 1<=pi<=106 ,1<=M<=10000,1<=ki<=109。 

这个题看到这数据范围就是二分的题 但是我还是wa了两次 最后一次也没改啥 想交一下看看多少分没想到就ac了 

#include<bits/stdc++.h>
using namespace std;
long long a[1000005];
long long p[1000005];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>p[i];
        a[i]+=a[i-1];
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        int x;
        scanf("%d",&x);
        int l=0,r=n;
        while(l<r){
            int mid=(l+r)>>1;
            if(a[mid]>=x)r=mid;
            else l=mid+1;
        }
        cout<<p[r]<<" ";
    }
    return 0;
}

问题 N: 求素数I

时间限制: 1.000 Sec  内存限制: 128 MB
提交 状态

题目描述

现给你N个0~9的数字并排成了一列,同时还给出了一个取数长度L。规定先从第1个数字开始从左往右连续取L个数字,拼成一个长度为L位(最高位为0的L-1位数除外)的数,然后从第2个数字开始从左往右连续取L个数字……,这样,最后最多可以得到N-L+1个L位数。现在请你将这些L位数中的素数按从小到大的顺序输出(如果产生重复,只需输出一个)。

输入

输入共有两行。
第一行为N和L,中间用空格隔开。(1≤N≤100,1≤L≤7)第二行为N个0~9的数字,中间用空格隔开。

输出

输出只有一行,含全部满足条件的素数,中间用逗号隔开。

样例输入 Copy

10 3
8 9 1 0 2 3 5 4 7 6

样例输出 Copy

547
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e7+1;
LL n,l,a[1005],b[N],ans,t,q[200];
void isprime()
{
    for(int i=2;i<=sqrt(N);i++){
        if(b[i]==0){
            for(int j=i*i;j<N;j+=i){
                b[j]=1;
            }
        }
    }

}
int main()
{
    isprime();
    cin>>n>>l;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n-l+1;i++){
        LL sum=0;
        if(a[i]==0)continue;
        for(int j=i;j<=i+l-1;j++){
            sum=sum*10+a[j];
        }
        if(b[sum]==0)q[t++]=sum;
    }
    sort(q,q+t);
    int i=0,j=1;
    while(j<t){
        if(q[i]!=q[j])q[++i]=q[j];
        j++;
    }
    for(int j=0;j<=i;j++){
        if(j==0)cout<<q[j];
        else cout<<","<<q[j];
    }
    return 0;
}

 先打表吧 要不然判断素数会超时的

 

问题 P: Card Game for Three

时间限制: 1.000 Sec  内存限制: 128 MB
提交 状态

题目描述

Alice, Bob and Charlie are playing Card Game for Three, as below:

At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.
The players take turns. Alice goes first.
If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)
If the current player's deck is empty, the game ends and the current player wins the game.
You are given the initial decks of the players. More specifically, you are given three strings SA, SB and SC. The i-th (1≦i≦|SA|) letter in SA is the letter on the i-th card in Alice's initial deck. SB and SC describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints
1≦|SA|≦100
1≦|SB|≦100
1≦|SC|≦100
Each letter in SA, SB, SC is a, b or c.

输入

The input is given from Standard Input in the following format:
SA
SB
SC

输出

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.

样例输入 Copy

aca
accc
ca

样例输出 Copy

A

提示

The game will progress as below:
Alice discards the top card in her deck, a. Alice takes the next turn.
Alice discards the top card in her deck, c. Charlie takes the next turn.
Charlie discards the top card in his deck, c. Charlie takes the next turn.
Charlie discards the top card in his deck, a. Alice takes the next turn.
Alice discards the top card in her deck, a. Alice takes the next turn.
Alice's deck is empty. The game ends and Alice wins the game.

#include<bits/stdc++.h>
using namespace std;
string a[4];
int len[4];
char who;
int h1,h2,h3;
int main()
{
    for(int i=1;i<=3;i++)cin>>a[i],len[i]=a[i].size();
    who='a';
    while(1){
        if(who=='a'){
            if(h1==len[1]){
                cout<<"A\n";
                break;
            }
            who=a[1][h1++];
        }
        if(who=='b'){
            if(h2==len[2]){
                cout<<"B\n";
                break;
            }
            who=a[2][h2++];
        }
        if(who=='c'){
            if(h3==len[3]){
                cout<<"C\n";
                break;
            }
            who=a[3][h3++];
        }
    }

    return 0;
}

这个是三个小朋友玩游戏的题 难点就在于这个循环要怎么做 

 

还有好多题都不会打 希望有这场比赛的 大佬来指点我一下

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值