codeforces-745【思维】

题目链接:点击打开链接

A. Hongcow Learns the Cyclic Shift
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.

Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on.

Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.

Input

The first line of input will be a single string s (1 ≤ |s| ≤ 50), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'–'z').

Output

Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.

Examples
input
abcd
output
4
input
bbb
output
1
input
yzyz
output
2
Note

For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".

For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".

For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".


思路:把字符串按照题意做 len 次循环,然后判断有没有出现过就好了

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<map>
using namespace std;
string str;
map<string,bool> M; 
int main()
{
	while(cin>>str)
	{
		M.clear();
		int len=str.length();
//		cout<<str.size()<<endl;
		int ans=0;
		for(int i=1;i<=len;i++)
		{
			if(!M[str])
			{
				ans++;
				M[str]=1;
			}
			str=str[len-1]+str;
			str.erase(str.end()-1,str.end());
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char str[55][55];
int main()
{
	while(~scanf("%s",str[0]))
	{
		int len=strlen(str[0]);
		int ans=1;
		for(int i=1;i<len;i++)
		{
			str[i][0]=str[i-1][len-1];
			for(int j=1;j<len;j++)
			{
				str[i][j]=str[i-1][j-1];
			}
			bool flag=1;
			for(int j=0;j<i;j++)
			{
				if(strcmp(str[i],str[j])==0)
				{
					flag=0;
					break;
				}
			}
			if(flag)
				ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}*/

题目链接: 点击打开链接

B. Hongcow Solves A Puzzle
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Hongcow likes solving puzzles.

One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.

The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.

You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position.

Input

The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.

The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.

It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region.

Output

Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.

Examples
input
2 3
XXX
XXX
output
YES
input
2 2
.X
XX
output
NO
input
5 5
.....
..X..
.....
.....
.....
output
YES
Note

For the first sample, one example of a rectangle we can form is as follows

111222
111222

For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.

In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:

.....
..XX.
.....
.....
.....

大意:给你一块区域,有 ' X ' ,有 ' . ' ,整个区域不能进行旋转或反转,问两个相同的区域拼凑后 ' X ' 是否能构成一个矩形,其中 ' . ' 是空白区域,可以放  ' X ' 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
char s[510][510];
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		int min_r=510,max_r=0;
		int min_c=510,max_c=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=m;j++)
			{
				cin>>s[i][j];
				if(s[i][j]=='X')
				{
					min_r=min(i,min_r);
					max_r=max(i,max_r);
					min_c=min(j,min_c);
					max_c=max(j,max_c);
				}
			}
		}
		bool flag=1;
		for(int i=min_r;i<=max_r;i++)
		{
			for(int j=min_c;j<=max_c;j++)
			{
				if(s[i][j]!='X')
				{
					flag=0;
					break;
				}
			}
			if(!flag)
				break;
		}
		if(flag)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用的内容,CodeForces的初始分由1500改为了1400,并且前六场的初始分配如下:第一场500分,第二场350分,第三场250分,第四场150分,第五场100分,第六场50分。所以,根据你在第一场的表现分为368,你的总分应为868(1400+368)。接下来的五场比赛,你的表现分将根据具体情况来决定。每场比赛的表现分会对你的总分产生影响。 关于其他引用和的代码,它们似乎是一些针对不同情况进行计算和输出的算法,并不直接涉及到CodeForces上的分数计算。所以,如果你有关于CodeForces上分的具体问题,请提供更多详细信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [CodeForces前六场定级赛赋分规则(2020.5修订)及各段位对应分数段](https://blog.csdn.net/Sunshine_xiaohao/article/details/112106625)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [CodeForces上分日记 (思维题)(A. Garland)1809A (Educational Round 145 For Div.2)](https://blog.csdn.net/weixin_60375636/article/details/130243342)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [【codeforces】一切为了上分:骚操作合集](https://blog.csdn.net/weixin_45497996/article/details/109157711)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值