7.12训练

2174: Help Victoria the Wise
时间限制: 2 Sec  内存限制: 256 MB
提交: 21  解决: 9
[提交][状态][讨论版]
题目描述
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.


The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube)


Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem.


Input
The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} − they are the colors of gems with which the box should be decorated.


Output
Print the required number of different ways to decorate the box.


Examples
Input
YYYYYY
Output
1
Input
BOOOOB
Output
2
Input
ROYGBV
Output

30


心得:题目理解错了,后来问了同学才做出来,没看到在正方体上

题意:在一个正方体上涂色,给出可以涂的颜色,求有多少种涂的方法,若可以通过旋转得到的两种情况视为同一种情况。

思路:枚举出来,总共11种;

1、6——1;

2、1,5——1;

3、2,4——2;

4、3,3——2;

5、1,1,4——2;

6、1,2,3——3;

7、2,2,2——6;//考虑两个面涂好,再涂其他面,之后的考虑方法相同

8、1,1,1,3——5;

9、1,1,2,2——8;

10、1,1,1,1,2——15;

11、1,1,1,1,1,1——30;

#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main(void)
{
	char a[20];
	int b[500],i;
	while(~scanf("%s",a))
	{
		memset(b,0,sizeof(b));
		for(i=0;i<6;i++)
		{
			if(a[i]=='R') b[0]++;
			else if(a[i]=='O') b[1]++;
			else if(a[i]=='Y') b[2]++;
			else if(a[i]=='G') b[3]++;
			else if(a[i]=='B') b[4]++;
			else if(a[i]=='V') b[5]++;
		}
		sort(b,b+6,cmp);
		if(b[0]==6||b[0]==5&&b[1]==1) printf("1\n");
		else if(b[0]==4&&b[1]==2||b[0]==3&&b[1]==3||b[0]==4&&b[1]==1&&b[2]==1) printf("2\n");
		else if(b[0]==3&&b[1]==2&&b[2]==1) printf("3\n");
		else if(b[0]==2&&b[1]==2&&b[2]==2) printf("6\n");
		else if(b[0]==3&&b[1]==1&&b[2]==1&&b[3]==1) printf("5\n");
		else if(b[0]==2&&b[1]==2&&b[2]==1&&b[3]==1) printf("8\n");
		else if(b[0]==2&&b[1]==1&&b[2]==1&&b[3]==1&&b[4]==1) printf("15\n");
		else if(b[0]==1&&b[1]==1&&b[2]==1&&b[3]==1&&b[4]==1&&b[5]==1) printf("30\n");
    }
	return 0;
}
2184: Friends
时间限制: 2 Sec  内存限制: 256 MB
提交: 20  解决: 10
[提交][状态][讨论版]
题目描述
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.


The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"


Igor just couldn't get why the required minimum is 6 people. "Well, that's the same for five people, too!" − he kept on repeating in his mind. − "Let's take, say, Max, Ilya, Vova − here, they all know each other! And now let's add Dima and Oleg to Vova − none of them is acquainted with each other! Now, that math is just rubbish!"


Igor K. took 5 friends of his and wrote down who of them is friends with whom. Now he wants to check whether it is true for the five people that among them there are either three pairwise acquainted or three pairwise not acquainted people.


Input
The first line contains an integer m (0≤m≤10), which is the number of relations of acquaintances among the five friends of Igor's.


Each of the following m lines contains two integers ai and bi (1≤ai,bi≤5;ai≠bi), where (ai,bi) is a pair of acquainted people. It is guaranteed that each pair of the acquaintances is described exactly once. The acquaintance relation is symmetrical, i.e. if x is acquainted with y, then y is also acquainted with x.


Output
Print "FAIL", if among those five people there are no either three pairwise acquainted or three pairwise unacquainted people. Otherwise print "WIN".


Examples
Input
4
1 3
2 3
1 4
5 3
Output
WIN
Input
5
1 2
2 3
3 4
4 5
5 1
Output
FAIL
输入
输出
样例输入
样例输出
提示
来源


[提交][状态][讨论版]



心得:这道题就是我想错了,我原以为要满足必须有每个点要么有3个边,要么没3个边,后来发现又变成要么有三个以上的边,或者没有边。

思路:以上想法是错的,题意为一个图中有3两两相连的点或者没有,及不出现5圆环则输出“WIN”不然输出“FAIL”。

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int m,a,b,i;
	int v[10]={0};
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&a,&b);
		v[a]++;
		v[b]++;
	}
	int cnt=0;
	for(i=1;i<=5;i++) 
	{
		if(v[i]==2) cnt++;
	}
	if(cnt==5) printf("FAIL\n");
	else printf("WIN\n");
	return 0;
}


2183: Hockey
时间限制: 2 Sec  内存限制: 256 MB
提交: 13  解决: 6
[提交][状态][讨论版]
题目描述
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1,s2,...,sn. All those strings consist of uppercase and lowercase Latin letters. String w has the length of |w|, its characters are numbered from 1 to |w|.


First Petya should find all the occurrences of forbidden substrings in the w string. During the search of substrings the case of letter shouldn't be taken into consideration. That is, strings "aBC" and "ABc" are considered equal.


After that Petya should perform the replacement of all letters covered by the occurrences. More formally: a letter in the position i should be replaced by any other one if for position i in string w there exist pair of indices l,r (1≤l≤i≤r≤|w|) such that substring w[l...r] is contained in the collection s1,s2,...,sn, when using case insensitive comparison. During the replacement the letter's case should remain the same. Petya is not allowed to replace the letters that aren't covered by any forbidden substring.


Letter letter (uppercase or lowercase) is considered lucky for the hockey players. That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. Help Petya to find such resulting string. If there are several such strings, find the one that comes first lexicographically.


Note that the process of replacements is not repeated, it occurs only once. That is, if after Petya's replacements the string started to contain new occurrences of bad substrings, Petya pays no attention to them.


Input
The first line contains the only integer n (1≤n≤100) − the number of forbidden substrings in the collection. Next n lines contain these substrings. The next line contains string w. All those n+1 lines are non-empty strings consisting of uppercase and lowercase Latin letters whose length does not exceed 100. The last line contains a lowercase letter letter.


Output
Output the only line − Petya's resulting string with the maximum number of letters letter. If there are several answers then output the one that comes first lexicographically.


The lexicographical comparison is performed by the standard < operator in modern programming languages. The line a is lexicographically smaller than the line b, if a is a prefix of b, or there exists such an i (1≤i≤|a|), that ai<bi, and for any j (1≤j<i) aj=bj. |a| stands for the length of string a.


Examples
Input
3
bers
ucky
elu
PetrLoveLuckyNumbers
t
Output
PetrLovtTttttNumtttt
Input
4
hello
party
abefglghjdhfgj
IVan
petrsmatchwin
a
Output
petrsmatchwin
Input
2
aCa
cba
abAcaba
c
Output
abCacba


心得:英语不好是硬伤

题意:先输入一个n再输入n个禁止出现的字符串s,再输入一个样例字符串s1,最后输入一个替换字符ch(小写字母),

如果样例字符串中有禁止出现的子串则进行替换,如果要进行替换的字符与ch不同,直接替换,但大小写的格式与s1中的相同,

如果替换的字符与ch相同,安字典序进行替换(字典序:如果是‘a’,换成比a大的‘b’,否则全部替换为‘a’),替换只进行一次,不重复进行。

思路:另外定义一个字符串s2,先让s2=s1,在比较s1中是否会出现禁止子串,如果出现,进行替换。

替换过程仅在s2中进行,s1要保持不变,而且“That's why Petya should perform the changes so that the letter occurred in the resulting string as many times as possible. ”表示要替换尽可能多的字符。eg:如果出现abc,abcde的禁止子串,且均为s1的子串,则要用abcde替换。(一开始就是没注意到这一点才一直WA的)

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	char ch;
	int n,i,j,k,tp,fg;
	scanf("%d",&n);
		string s[120],s1,s2;
		for(i=0;i<n;i++)
		cin>>s[i];
		cin>>s1;
		cin>>ch;
		s2=s1;
		for(i=0;i<s1.size();i++)
		{
			for(j=0;j<n;j++)
			{
				k=0,tp=i;
				while((s[j][k]==s1[tp]||s[j][k]==s1[tp]+32||s[j][k]==s1[tp]-32)&&k<s[j].size()) 
				tp++,k++;
				if(k>=s[j].size())
				{
					for(tp=i;tp<i+s[j].size();tp++)
					{
						fg=0;
						if(s1[tp]>='A'&&s1[tp]<='Z') s1[tp]=s1[tp]+32,fg=1;
						if(s1[tp]!=ch) 
						{
							if(fg) s2[tp]=ch-32;
							else s2[tp]=ch;
						}
						else
						{
							if(fg) 
							{
								if(s1[tp]=='a') s2[tp]='B';
								else if(s1[tp]>='b'&&s1[tp]<='z') s2[tp]='A';
							}
							else 
							{
								if(s1[tp]=='a') s2[tp]='b';
								else if(s1[tp]>='b'&&s1[tp]<='z') s2[tp]='a'; 
							}
						}
						if(fg) s1[tp]=s1[tp]-32;
					}
				} 
			}
		}
		for(i=0;i<s1.size();i++) printf("%c",s2[i]);
		printf("\n");
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值