7月9日训练

2019CCPC湖南全国邀请赛(广东省赛、江苏省赛)

E.Hello XTCPC

Problem Description

You have a string of lowercase letters.You need to find as many sequence “xtCpc” as possible.But letters in the same position can only be used once。

Input

The input file contains two lines.

The first line is an integer n show the length of string.(1≤n≤2×105)

The second line is a string of length n consisting of lowercase letters and uppercase letters.

Output

The input file contains an integer show the maximum number of different subsequences found.

Sample Input

10
xtCxtCpcpc

Sample Output

2

思路分析

1.注意sequence是序列,就是说可以不连续,从样例中也可以看出来.那么怎么求序列xtCPc出现的个数呢?刚开始想的统计每个字母出现的个数,但是忽略了序列中字母顺序的问题,如果暴力的话O(n^2)也是要t的.
怎样扫一遍就能算出答案呢?可以开一个数组从前往后记录元素的个数,遇到x就加一,遇到t的话要把x的个数先减一,然后再自增.这样的话就可以保证t的个数是有效的(如果记录t的时候x不足1个,那么这个t是无效的).这样序列中有多少序列xtcPc就可以转化成求有多少个有效的c.
2.虽然题目中没说,但是要用多组输入.所以比赛的时候尽量用多组输入,即使只有一组的话也不会wa

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
 
int n;
char a[maxn];
int b[10];

int main(){
	while(cin>>n){
		cin>>a;
		memset(b,0,sizeof(b));	
		for(int i=0;i<n;i++){
			if(a[i]=='x'){
				b[1]++;
			}	
			if(a[i]=='t'){
				if(b[1]>0){
					b[1]--;
					b[2]++;
				}
			}	
			if(a[i]=='C'){
				if(b[2]>0){
					b[2]--;
					b[3]++;
				}			
			}	
			if(a[i]=='p'){
				if(b[3]>0){
					b[3]--;
					b[4]++;
				}			
			}
			if(a[i]=='c'){
				if(b[4]>0){
					b[4]--;
					b[5]++;
				}			
			}	
		}
		
		cout<<b[5]<<endl;		
	}

	return 0;
}

K.SSY and JLBD

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1184 Accepted Submission(s): 588

Problem Description

Mahjong is a board game with a long history. But Mahjong has different rules in different city.

A deck of mahjong consists of 136 cards. It contains 1-9 card in three suits,and Seven kinds of word card(“dong”,“nan”,“xi”,“bei”,“zhong”,“fa”,“bai”),there are 4 same cards for each kind of card in a deck of mahjong .

In a mysterious country, the rules of mahjong are very simple.In the game,each Player has 14 cards.There are only two ways people can win the game:

  1. shisanyao:You should have all 1 and 9 card in three suits and seven kinds of word card at the same time,and an extra card with any kind of 1 and 9 or word.

  2. jiulianbaodeng:Firstly,You should make sure that you have the same suit in your hand.Secondly, for card “1” and card “9”,you should have at least three . but for card “2” to card “8”,at least one.For example, both “11112345678999” and “11122345678999” can win the game.

Now you know a player’s 14 cards. Please judge which card type he can use to win the game.

Input

The input file contains 14 lines.Each line has a string representing a card.

For three suits of card “1” to card “9”,We use two characters for the type,the first character a is number 1 to 9,and the second character b represents the suit.(a∈{1,2,3,4,5,6,7,8,9},b∈{s,p,w})

For the word cards,as shown in the description,we use full spelling pinyin represent them.

Output

If player ‘s card meet the “shisanyao” condition, you should output “shisanyao!”.

If player ‘s card meet the “jiulianbaodeng” condition, you should output “jiulianbaodeng!”.

Otherwise,you should output “I dont know!”.

Sample Input

1w
5w
2w
6w
5w
9w
9w
7w
1w
3w
9w
4w
1w
8w

Sample Output

jiulianbaodeng!

思路分析

模拟

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;

int main(){	
	string x;
	int s[20],p[20],w[20];
	set<string> S;
	for(int i=1;i<=14;i++){
		cin>>x;
		if(x[0]<='9'&&x[0]>='0'){
			int t=x[0]-'0';
			if(x[1]=='s')	s[t]++;
			else if(x[1]=='p')	p[t]++;
			else if(x[1]=='w')	w[t]++;
		}else{
			S.insert(x);
		}
	}
	
	if(S.size()==7){
		if(s[1]&&s[9]&&p[1]&&p[9]&&w[1]&&w[9]){
			cout<<"shisanyao!"<<endl;
		}else{
			cout<<"I dont know!"<<endl;
		}
	}else{
		int n[20];
		for(int i=1;i<=9;i++){
			n[i]=s[i]+p[i]+w[i];
		}
		int ans;
		if(n[1]>1&&n[9]>1)
			ans=1;
		else
			ans=0;
		for(int i=2;i<=8;i++)
			if(!n[i]){
				ans=0;
				break;
			}
		if(ans==1)
			cout<<"jiulianbaodeng!"<<endl;
		else
			cout<<"I dont know!"<<endl;
	}
	return 0;
}

Can you raed it croretcly?

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1680 Accepted Submission(s): 783

Problem Description

Do you feel weird when reading the problem title? You can understand word meanning correctly even if its spelling is wrong.
According to research, if the initial and last letter of the word are right, and just swap the others, human can correct the spelling of the word automatically.
Now, giving you a word and its correct spelling, can you correct it automatically?

Input

The input contains several test cases.
Each test case consists of one line with two strings, each string only contains lowercase letter, and its length is no more than 20.

Output

Output “Equal” when the two strings are same; output “Yes” when you can correct it, otherwise outoput “No”.

Sample Input

raed read
it it
croretcly correctly
raed dear

Sample Output

Yes
Equal
Yes
No

思路分析

因为忘了加!=EOF,导致一直超时,所以硬生生把一道几分钟就要a的签到题做了好长时间,用了两个版本,一个用sort排序判断时候相同,另一种用数组判断,把复杂度从O(n*logn)降成了O(n).

AC代码

#include<bits/stdc++.h>
using namespace std;
int main(){
    char x[25];
    char y[25];
    while(scanf("%s",x)!=EOF){
    	scanf("%s",y);
        if(strcmp(x,y)==0){
            cout<<"Equal"<<endl;
            continue;
        }else if(strlen(x)!=strlen(y)){
            cout<<"No"<<endl;
        }else{
            int len=strlen(x);
            if(x[0]==y[0]&&x[len-1]==y[len-1]){
                sort(x,len+x);
                sort(y,len+y);
                if(strcmp(x,y)==0){
                    cout<<"Yes"<<endl;
                }else
                    cout<<"No"<<endl;                
            }else
                cout<<"No"<<endl;
        }
    }
    return 0;
}

算法:dp

1015. 摘花生

Hello Kitty想摘点花生送给她喜欢的米老鼠。

她来到一片有网格状道路的矩形花生地(如下图),从西北角进去,东南角出来。

地里每个道路的交叉点上都有种着一株花生苗,上面有若干颗花生,经过一株花生苗就能摘走该它上面所有的花生。

Hello Kitty只能向东或向南走,不能向西或向北走。

问Hello Kitty最多能够摘到多少颗花生。

1.gif

输入格式

第一行是一个整数T,代表一共有多少组数据。

接下来是T组数据。

每组数据的第一行是两个整数,分别代表花生苗的行数R和列数 C。

每组数据的接下来R行数据,从北向南依次描述每行花生苗的情况。每行数据有C个整数,按从西向东的顺序描述了该行每株花生苗上的花生数目M。

输出格式

对每组输入数据,输出一行,内容为Hello Kitty能摘到得最多的花生颗数。

数据范围

1≤T≤100,
1≤R,C≤100,
0≤M≤1000

输入样例:

2
2 2
1 1
3 4
2 3
2 3 4
1 6 5

输出样例:

8
16

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=110;

int t;
int r,c,a[maxn][maxn];
int dp[maxn][maxn];//表示到该点能摘到最多的花生颗数 

int main(){
	scanf("%d",&t);
	while(t--){		
		scanf("%d %d",&r,&c);
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++){
				scanf("%d",&a[i][j]);
			}
		} 
		
		for(int i=1;i<=r;i++){
			for(int j=1;j<=c;j++){
				dp[i][j]=max(dp[i-1][j]+a[i][j],dp[i][j-1]+a[i][j]);
			}
		} 
		
//		for(int i=1;i<=r;i++){
//			for(int j=1;j<=c;j++){
//				cout<<dp[i][j]<<" ";
//			}
//			cout<<endl;
//		} 
		printf("%d\n",dp[r][c]);
	}
	return 0;
}

1018. 最低通行费

一个商人穿过一个N×N的正方形的网格,去参加一个非常重要的商务活动。

他要从网格的左上角进,右下角出。

每穿越中间1个小方格,都要花费1个单位时间。

商人必须在(2N-1)个单位时间穿越出去。

而在经过中间的每个小方格时,都需要缴纳一定的费用。

这个商人期望在规定时间内用最少费用穿越出去。

请问至少需要多少费用?

注意:不能对角穿越各个小方格(即,只能向上下左右四个方向移动且不能离开网格)。

输入格式

第一行是一个整数,表示正方形的宽度N。

后面N行,每行N个不大于100的整数,为网格上每个小方格的费用。

输出格式

输出一个整数,表示至少需要的费用。

数据范围

1≤N≤100

输入样例:

5
1 4 6 8 10
2 5 7 15 17
6 8 9 18 20
10 11 12 19 21
20 23 25 29 33

输出样例:

109

样例解释

样例中,最小值为109=1+2+5+7+9+12+19+21+33。

思路分析

刚刚那道题的代码其实写错了,什么错误呢?第一行第一列其实是需要初始化的,但是因为刚才那道题求的是最大值,(比如说求第一行的话,)0加上该点的值肯定是要小于左边的点的dp加上改点的值的,所以没有影响.但是这道题求的是最小值,所以会出错.
这道题要先求第一行和第一类的值,再求其他的值.
在这里插入图片描述

AC代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=110;

int n,a[maxn][maxn];
int dp[maxn][maxn];//表示到该点能摘到最多的花生颗数 

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		} 
	
	for(int i=1;i<=n;i++)
		dp[1][i]=dp[1][i-1]+a[1][i];
	for(int i=2;i<=n;i++)
		dp[i][1]=dp[i-1][1]+a[i][1];
		
	for(int i=2;i<=n;i++)
		for(int j=2;j<=n;j++){
			dp[i][j]=min(dp[i-1][j]+a[i][j],dp[i][j-1]+a[i][j]);
		}
	
//	for(int i=1;i<=n;i++){
//		for(int j=1;j<=n;j++){
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	} 
	
	printf("%d",dp[n][n]);
	return 0;
}```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的记忆游戏(附源代码)   项目:JavaScript 记忆游戏(附源代码) 记忆检查游戏是一个使用 HTML5、CSS 和 JavaScript 开发的简单项目。这个游戏是关于测试你的短期 记忆技能。玩这个游戏 时,一系列图像会出现在一个盒子形状的区域中 。玩家必须找到两个相同的图像并单击它们以使它们消失。 如何运行游戏? 记忆游戏项目仅包含 HTML、CSS 和 JavaScript。谈到此游戏的功能,用户必须单击两个相同的图像才能使它们消失。 点击卡片或按下键盘键,通过 2 乘 2 旋转来重建鸟儿对,并发现隐藏在下面的图像! 如果翻开的牌面相同(一对),您就赢了,并且该对牌将从游戏中消失! 否则,卡片会自动翻面朝下,您需要重新尝试! 该游戏包含大量的 javascript 以确保游戏正常运行。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,通过单击 memorygame-index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值