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

点个赞再走呗
L

#include
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
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
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;
}

你可能感兴趣的:(题目)