Now there are K people play Halli Galli game.They will play N turns in all,in the order of the first player,the second player,⋯,the K player,the first player,⋯.
In one turn,the player will display a card on his side,if there are a
kinds of fruit which its total ammount is exactly 5 in all sides,the bell will be pushed a times in this turn.Notices that the previous card will be covered by the current card.Now you have to calculate the total times they push the bell in N turns.
Input
There are T(1≤T≤100) test cases in this problem.For every test cases,the first line has two integers N(1≤N≤100), K(1≤K≤6)
respectively representing the number of turns, the number of people.
The next N rows with a char ch and an integer x(1≤x≤5) ,respectively representing the type of fruit on the card,the ammount of fruit on the card. There are always four kinds of fruit,respectively ‘A’ ,‘B’,‘G’,‘P’(Apple,Banana,Grape,Pear).
Output
For every test case, output the answer in a line.
Example Input
1
5 3
A 5
B 2
B 3
G 1
P 5
Output
6
题目链接:https://vjudge.net/problem/Gym-102801G
题解:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int num_key[7];
memset(num_key,0,sizeof(num_key));
char ch_key[7];
memset(ch_key,'0',sizeof(ch_key));
int sum=0;
for(int i=0;i<n;i++)
{
int key;
char ch;
getchar();
cin>>ch>>key;
num_key[i%k]=key;
ch_key[i%k]=ch;
int a=0,b=0,g=0,p=0;
for(int j=0;j<k;j++)
{
if(ch_key[j]=='A')
{
a+=num_key[j];
}
else if(ch_key[j]=='B')
{
b+=num_key[j];
}
else if(ch_key[j]=='G')
{
g+=num_key[j];
}
else if(ch_key[j]=='P')
{
p+=num_key[j];
}
}
if(a==5)
{
sum++;
}
if(b==5)
{
sum++;
}
if(g==5)
{
sum++;
}
if(p==5)
{
sum++;
}
}
cout<<sum<<endl;
}
return 0;
}
此题由于我读错了题目信息,最后得知解法异常无语,我努力了很久的没做出来的题,我还是得把我之前想法的代码附上,表示自己的努力!错的原因就是我当时不知道题目中那个‘a’表示的是一个的意思,还是表示a种的意思,我就按了后者,毕竟后面是kinds,前面是are,英语不太好就是有些吃亏哈!
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct node
{
char ch;
int key;
} a[7];
int Meiju(int k,int turn)
{
set<int>s;
int sum=0;
if(turn<k)
{
for(int i=1; i<=turn; i++)
{
if(a[i].key==5)
{
s.insert(a[i].ch);
sum+=s.size();
s.clear();
}
}
for(int i=1; i<turn; i++)
{
for(int j=i+1; j<=turn; j++)
{
if(a[i].key+a[j].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
sum+=s.size();
s.clear();
}
}
}
for(int i=1; i<turn-1; i++)
{
for(int j=i+1; j<turn; j++)
{
for(int w=j+1; w<=turn; w++)
{
if(a[i].key+a[j].key+a[k].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
s.insert(a[w].ch);
sum+=s.size();
s.clear();
}
}
}
}
for(int i=1; i<turn-2; i++)
{
for(int j=i+1; j<turn-1; j++)
{
for(int w=j+1; w<turn; w++)
{
for(int u=k+1; u<=turn; u++)
{
if(a[i].key+a[j].key+a[w].key+a[u].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
s.insert(a[w].ch);
s.insert(a[u].ch);
sum+=s.size();
s.clear();
}
}
}
}
}
for(int i=1; i<turn-3; i++)
{
for(int j=i+1; j<turn-2; j++)
{
for(int w=j+1; w<turn-1; w++)
{
for(int u=k+1; u<turn; u++)
{
for(int v=u+1; u<=turn; u++)
{
if(a[i].key+a[j].key+a[w].key+a[u].key+a[v].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
s.insert(a[w].ch);
s.insert(a[u].ch);
s.insert(a[v].ch);
sum+=s.size();
s.clear();
}
}
}
}
}
}
}
else
{
for(int i=1; i<=k; i++)
{
if(a[i].key==5)
{
s.insert(a[i].ch);
sum+=s.size();
s.clear();
}
}
for(int i=1; i<k; i++)
{
for(int j=i+1; j<=k; j++)
{
if(a[i].key+a[j].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
sum+=s.size();
s.clear();
}
}
}
for(int i=1; i<k-1; i++)
{
for(int j=i+1; j<k; j++)
{
for(int w=j+1; w<=k; w++)
{
if(a[i].key+a[j].key+a[w].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
s.insert(a[w].ch);
sum+=s.size();
s.clear();
}
}
}
}
for(int i=1; i<k-2; i++)
{
for(int j=i+1; j<k-1; j++)
{
for(int w=j+1; w<k; w++)
{
for(int u=k+1; u<=k; u++)
{
if(a[i].key+a[j].key+a[w].key+a[u].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
s.insert(a[w].ch);
s.insert(a[u].ch);
sum+=s.size();
s.clear();
}
}
}
}
}
for(int i=1; i<k-3; i++)
{
for(int j=i+1; j<k-2; j++)
{
for(int w=j+1; w<k-1; w++)
{
for(int u=k+1; u<k; u++)
{
for(int v=u+1; u<=k; u++)
{
if(a[i].key+a[j].key+a[w].key+a[u].key+a[v].key==5)
{
s.insert(a[i].ch);
s.insert(a[j].ch);
s.insert(a[w].ch);
s.insert(a[u].ch);
s.insert(a[v].ch);
sum+=s.size();
s.clear();
}
}
}
}
}
}
}
return sum;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k;
cin>>n>>k;
int num_key;
char ch_key;
int sum=0;
for(int i=1; i<=n; i++)
{
getchar();
cin>>ch_key>>num_key;
if(i%k==0)
{
a[k].ch=ch_key;
a[k].key=num_key;
sum+=Meiju(k,k);
}
else
{
a[i%k].ch=ch_key;
a[i%k].key=num_key;
if(i==i%k)
{
sum+=Meiju(k,i%k);
}
else
{
sum+=Meiju(k,k);
}
}
}
cout<<sum<<endl;
}
return 0;
}