Contest2676 - 2021ACM俱乐部后备营个人训练赛第14场A(全排列) F(扑克牌) L题解

点个赞再走呗
L

#include<bits/stdc++.h>
int cnt=0;
using namespace std;

int cmp(int a,int b)
{
    return a>b;
}
typedef long long ll;
const int maxn=1e6+199;
int len1,len2,len3;
double a[maxn];
double b[maxn]={0};
char c[maxn];
double k;
int n,m;
int sum=0;

int main(){
  cin>>n;
  for(int i=1;i<=n;i++)  cin>>a[i];

  for(int i=1;i<=n;i++)  b[i]=b[i-1]+a[i];
  for(int i=0;i<=n;i++)
  {
      for(int j=i+2;j<=n;j++)
      {
            k=(b[j]-b[i])/(j*1.0-i*1.0);
            for(int l=i+1;l<=j;l++)
            {
                if(a[l]==k)
                {
                    sum++;
                    break;
                }
            }
      }
  }
  cout<<sum+n;
    return 0;
}

F

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>
int cnt=0;
using namespace std;
 
int cmp(int a,int b)
{
    return a>b;
}
typedef long long ll;
const int maxn=1e6+199;
int len1,len2,len3;
char a[maxn];
char b[maxn];
char c[maxn];
int k,n,m;
int sum=0;
void zoua();
void zoub();
void zouc();
int s=0,ss=0,sss=0;
 
void zoua()
{
    s++;
 
    if(len1<s)
    {
        cout<<"A";
            return;
    }
    if(a[s-1]=='a')
   {
       zoua();
   }
   else if(a[s-1]=='b')
   {
       zoub();
   }
   else if(a[s-1]=='c')
   {
       zouc();
   }
 
}
 
void zoub()
{
    ss++;
        if(ss>len2)
    {
        cout<<"B";
            return;
    }
    if(b[ss-1]=='a')
   {
       zoua();
   }
   else if(b[ss-1]=='b')
   {
       zoub();
   }
   else if(b[ss-1]=='c')
   {
       zouc();
   }
}
 
void zouc()
{
    sss++;
    if(len3<sss)
    {
        cout<<"C";
            return;
    }
    if(c[sss-1]=='a')
   {
       zoua();
   }
   else if(c[sss-1]=='b')
   {
       zoub();
   }
   else if(c[sss-1]=='c')
   {
       zouc();
   }
}
int main(){
  scanf("%s%s%s",a,b,c);
   len1=strlen(a);
   len2=strlen(b);
   len3=strlen(c);
   if(a[s]=='a')
   {
       s++;
       zoua();
   }
   else if(a[s]=='b')
   {
       s++;
       zoub();
   }
   else if(a[s]=='c')
   {
       s++;
       zouc();
   }
 
    return 0;
}
 

A
全排列问题
如果会全排列就小kiss了

#include<bits/stdc++.h>
int cnt=0;
using namespace std;
typedef long long ll;
const int maxn=1e6+199;
ll a[maxn];
int k,n,m;
void dop()
{
 
    for (k = n - 1; k >= 1; k--)
    {
        if (a[k] < a[k + 1])
            break;
    }
    for (int i = n; i > k; i--)
    {
        if (a[i] > a[k])
        {
            swap(a[i], a[k]);
            break;
        }
    }
    sort(a + k + 1, a + n + 1);
}
int main(){
  cin>>n;
  cin>>m;
  for(int i=1;i<=n;i++)
    cin>>a[i];
  int i=0;
 while(i<m)
 {
     i++;
     dop();
 }
 for(int i=1;i<=n;i++)
 {
     if(i==1)
        cout<<a[i];
     else
        cout<<' '<<a[i];
 }
    return 0;
}
  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牛郎恋刘娘,刘娘念牛郎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值