Codeforces Round #627 (Div. 3) 补题

  • CF1324A Yet Another Tetris Problem

    长度为n的数组a中有一组数,可以任意使其中一项+2,问能否使a中所有项的值相同。

    感觉div.3的题目更多地在考简化问题的能力……比如原题目以俄罗斯方块作背景,让我想到的是能不能消除所有方块,导致代码很难写。但如果像上述一样简化题意,方向就很明确了:只要判断是否所有数均为偶数/均为奇数即可。

    CF1324A-代码
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<vector>
    #include<queue>
    using namespace std;
    
    int main()
    {
    	int a[110];
    	int kase;
    	cin>>kase;
    	while(kase--){
    		int n;
    		cin>>n;
    		a[0]=a[n+1]=0;
    		int ok=1;
    		for(int i=1;i<=n;i++){
    			cin>>a[i];
    			a[i]%2==0?a[i]=-1:a[i]=-2;//偶数记为-1,奇数记为-2
    			if(i==1) continue;
    			if(a[i]!=a[1]) ok=0;
    		}
    		if(ok) cout<<"YES"<<endl;
    		else cout<<"NO"<<endl;
    	}
    	return 0;
    }
    
    

  • CF1324B Yet Another Palindrome Problem

    判断a串中是否存在长度3及以上的回文子串

    简化问题:是否存在长度3的回文子串

    再简化:是否存在两个不相邻的相等元素

    简化到核心部分已经直接表明代码应该怎么写了……但是具体细节还是要展开一下:

    在遍历a串的过程中,用vis数组标记遇到的数字,并记录这个数字第一次出现时的下标。如果遍历到的数字是第二次遇到(\(vis[a[i]]!=0\)), 那么与第一次遇到该数字的位置作个距离计算,只要\(>1\)就能说明不相邻,可以作为首尾构成回文子串。

    CF1324B-代码

    ?

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<vector>
    #include<queue>
    using namespace std;
    
    int a[5010];
    int vis[5010];
    int main()
    {
    	int t;
    	cin>>t;
    	while(t--){
    		memset(a,0,sizeof(a));
    		memset(vis,0,sizeof(vis));
    		int n;
    		cin>>n;
    		int ok=0;
    		for(int i=1;i<=n;i++) {
    			cin>>a[i];
    			if(!vis[a[i]]) vis[a[i]]=i;
    			else if(i-vis[a[i]]>1) ok=1;
    		}
    		if(ok) cout<<"YES"<<endl;
    		else cout<<"NO"<<endl;
    	}
    	return 0;
    }
    
    

  • CF1324C Frog Jumps

    一只青蛙跳方格,只能向左向右跳。起点只能向右跳。其它格子写有L、R,代表青蛙在此方格上后的跳跃方向。青蛙可以选择一个距离\(d\),每一次跳跃都可以跳到距离\(<=d\)的格子上,问可以跳到终点的最小的\(d\)。

    逆向思考一波。显然终点只能由离它最近的R格子跳过去,但我当时的思考就到这里了,然后就卡住了……

    结合题意,对于两个间接相邻的R格子,总是可以从右边的R格子跳到左边的R格子(因为它们之间必定是连续的L),如果逆向思考,我们也只能这样跳回起点——也就是说,只要考虑路上所有间接或直接相邻的R格子的之间的距离,取其中最大值,就能保证选用的\(d\)可以从终点跳回起点。

    CF1324C-代码

    ?

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<set>
    #include<vector>
    #include<queue>
    using namespace std;
    
    int main()
    {
    	int t;
    	cin>>t;
    	while(t--){
    		string a="R";
    		string x;
    		cin>>x;
    		a+=x;
    		int last=0;
    		int m=0;
    		for(int i=0;i<a.length();i++){
    			if(a[i]==‘R‘){
    				m=max(m,i-last);
    				last=i;
    			}
    		}
    		int ans;
    		int k=a.length()-last;
    		ans=max(m,k);
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
    

原文地址:https://www.cnblogs.com/streamazure/p/12590358.html

时间: 2024-08-29 20:29:00

Codeforces Round #627 (Div. 3) 补题的相关文章

Codeforces Round #634 (Div. 3) 补题

A. Candies and Two Sisters 签到题,直接输出即可 代码 #include<bits/stdc++.h> #define INF 0x3f3f3f3f typedef long long ll; using namespace std; inline void read(int &p) { p=0;int flag=1;char c=getchar(); while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();} w

Codeforces Round #419 (Div. 1) 补题 CF 815 A-E

A-C传送门 D Karen and Cards 技巧性很强的一道二分优化题 题意很简单 给定n个三元组,和三个维度的上限,问存在多少三元组,使得对于给定的n个三元组中的每一个,必有两个维度严格小于. 首先我们根据一个维度(c维)对n个三元组排序,然后枚举答案在这个维度的取值. 此时序列被分成了两个部分,前半部分 满足所有c大于等于i 后半部分满足所有c严格小于i(即已有一个维度小于) 通过累计,我们知道此时前半部a维的最大值ma和b维的最大值mb. 显然可能存在的三元组答案,必然首先满足a维和

Codeforces Round #590 (Div. 3)补题

要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ? √ 解 E 待定 F 传送门 第一次接触状态压缩dp的题.这道题转换问题的思路非常巧妙. 原问题: 已知: 一个字符串,可进行不超过一次操作 操作限定: 选择某个子串,使其在原串中翻转 目的:使原串的特征值最大 串的特征值:串任意没有重复字符的子串,其包含字符的种类数 问题的转换: 首先选定一个子串a,之后再找到另一个子串b,使得a

Codeforces Round #617 (Div. 3) 补题记录

1296A - Array with Odd Sum 题意:可以改变数组中的一个数的值成另外一个数组中的数,问能不能使数组的和是个奇数 思路:签到,如果本来数组的和就是个奇数,那就OK 如果不是,就需要把数组中其中一个奇(偶)数改成偶(奇)数,相当于加一减一 所以测一下这个数组如果有个奇数并且还有个偶数就行 #include <cstdio> #include <iostream> #include <map> #include <set> #include

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #243 (Div. 1) A题

http://codeforces.com/contest/425/problem/A 题目链接: 然后拿出这道题目是很多人不会分析题目,被题目吓坏了,其中包括我自己,想出复杂度,一下就出了啊!真是弱! 直接暴力求出矩阵数值,然后枚举每一个[I,J];再O[N]判断,分配好在[I,J]区间的数和之内的数,再排序下SOLO了 CODE:#include <cstdio> #include <cstring>#include <queue>#include <vect

Codeforces Round #396 (Div. 2) D题Mahmoud and a Dictionary(并查集)解题报告

Mahmoud wants to write a new dictionary that contains n words and relations between them. There are two types of relations: synonymy (i. e. the two words mean the same) and antonymy (i. e. the two words mean the opposite). From time to time he discov

Codeforces Round #455 (Div. 2) D题(花了一个早自习补了昨晚的一道模拟QAQ)

D. Colorful Points You are given a set of points on a straight line. Each point has a color assigned to it. For point a, its neighbors are the points which don't have any other points between them and a. Each point has at most two neighbors - one fro

Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}

C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordina