Codeforces Round #288 (Div. 2)(稍看即懂,不解释)

2024-08-31 12:32
文章标签 codeforces round div 解释 288

本文主要是介绍Codeforces Round #288 (Div. 2)(稍看即懂,不解释),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目链接:http://codeforces.com/contest/508

//CF里可以直接int n; int a[n]。---奇葩1
//本该跳过而不是return 的,因为还没输入完(但可以A)---cf奇葩2

A:

#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>using namespace std;#define rofeach(i,x) for(epyt(x)i=x.rbegin();i!=x.rend();i++)
#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)
#define epyt(x) __typeof(x.rbegin())
#define type(x) __typeof(x.begin())
#define pii pair< int,int >
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define INF INT_MAX
#define nd second
#define st first
#define endl '\n'const int N = 1e5+5;
const int MAX = 1e9+5;int n,m,x,y,k,arr[1005][1005],asd;bool ctr(int x,int y){if(arr[x][y] && arr[x+1][y] && arr[x+1][y+1] && arr[x][y+1]) return 1;if(arr[x][y] && arr[x-1][y] && arr[x-1][y-1] && arr[x][y-1]) return 1;if(arr[x][y] && arr[x-1][y] && arr[x-1][y+1] && arr[x][y+1]) return 1;if(arr[x][y] && arr[x+1][y] && arr[x+1][y-1] && arr[x][y-1]) return 1;return 0;
}
int main(){scanf("%d %d %d",&n,&m,&k);FOR(i,1,k){	scanf("%d %d",&x,&y);		//CF里可以直接int n; int a[n]。---奇葩1arr[x][y] = 1;if(ctr(x,y)){cout << i << endl;return 0;		//本该跳过而不是return 的,因为还没输入完---cf奇葩2}}cout << 0 << endl;return 0;
}

B:

题意:给一个奇数,交换两个不同位置的数字,求能得到的最大的偶数。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;char s[100010], ts[100010];
int n;bool gao(char *s) {int pre = -1;for (int i = 0; i < n - 1; i ++) {if ((s[i] - '0') % 2 == 0) {	//左到右扫一遍,<则直接交换得答案,期间保留最后一位偶数下标if (s[i] < s[n - 1]) {swap(s[i], s[n - 1]);return true;}pre = i;}}if (pre != -1) {//若无<,则保留最后的一位偶数和末尾交换就是
        swap(s[pre], s[n - 1]);return true;}return false;
}int main() {scanf("%s", s);n = strlen(s);if ((s[n - 1] - '0') % 2 == 1) {strcpy(ts, s);bool sol = gao(ts);if (sol) {puts(ts);} else {puts("-1");}}return 0;
}

C:

题意:

有m只鬼要来Anya的房间,Anya要保证在鬼到来的那一秒保证房间里至少有r只蜡烛在燃烧。(每只鬼来临时间不同)

点蜡烛是在整秒时刻点(时间可以是负的),每秒只能点一只蜡烛。点亮后每只蜡烛会持续燃烧t秒后熄灭。求所需要的最少蜡烛数。

//☆思路还不错
#include<bits/stdc++.h>
using namespace std;
int ans,m,t,r,w[666],f[666];  //f[i];保持i秒时候亮的蜡烛数量
int main()
{cin>>m>>t>>r;for(int i=0;i<m;++i)cin>>w[i];sort(w,w+m);if(r>t)	return puts("-1");for(int i=0;i<m;++i){for(int j=w[i]-1;f[w[i]]<r;j--)//w[i]的前一秒开始点蜡烛{for(int k=j+1;k<=t+j;++k)//蜡烛持续亮t秒if(k>=1)f[k]++;	//t秒时亮的蜡烛数量+1ans++;	//j秒点了根蜡烛}}cout<<ans;
}

D. Tanya and Password
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n?+?2 characters. She has written all the possible n three-letter continuous substrings of the password on pieces of paper, one for each piece of paper, and threw the password out. Each three-letter substring was written the number of times it occurred in the password. Thus, Tanya ended up with n pieces of paper.


Then Tanya realized that dad will be upset to learn about her game and decided to restore the password or at least any string corresponding to the final set of three-letter strings. You have to help her in this difficult task. We know that dad's password consisted of lowercase and uppercase letters of the Latin alphabet and digits. Uppercase and lowercase letters of the Latin alphabet are considered distinct.


Input
The first line contains integer n (1?≤?n?≤?2·105), the number of three-letter substrings Tanya got.


Next n lines contain three letters each, forming the substring of dad's password. Each character in the input is a lowercase or uppercase Latin letter or a digit.


Output
If Tanya made a mistake somewhere during the game and the strings that correspond to the given set of substrings don't exist, print "NO".


If it is possible to restore the string that corresponds to given set of substrings, print "YES", and then print any suitable password option.


Sample test(s)
input
5
aca
aba
aba
cab
bac
output
YES
abacaba
input
4
abc
bCb
cb1
b13
output
NO
input
7
aaa
aaa
aaa
aaa
aaa
aaa
aaa
output
YES
aaaaaaaaa

如“abc”,拆成“ab”和“bc”,然后对ab和bc所属的编号加边。

#include <iostream>
#include <vector>
#include <algorithm>
#include<cstdio>
#include<string>
using namespace std;
vector<int> edges[66000];
int in[66000],out[66000],cnt[66000];
string ans;void dfs(int i)
{while(cnt[i]<edges[i].size())//cnt[i]:当edges[i].size()的下标{dfs(edges[i][cnt[i]++]);}ans+=(char)i%256;	//% 取后者,ex:s[1]*256+s[2]后者是s[2]
}
int main()
{int n,u,v,start=0,i;scanf("%d",&n);string s;for( i=0;i<n;++i){cin>>s;u=s[0]*256+s[1];v=s[1]*256+s[2];edges[u].push_back(v);in[u]++;  out[v]++;}start=u;int l=0,r=0;for(i=0;i<66000;++i){int d=in[i]-out[i];if(d==1){ l++; start=i; }else if(d==-1) r++;else if(d!=0){printf("NO\n");return 0;}}if(l>1 || r>1){printf("NO\n");return 0;}dfs(start);//cout<<char(u/256)<<" ans="<<ans<<endl;ans+=(char)(start/256);//cout<<" ans="<<ans<<endl;reverse(ans.begin(),ans.end());if(ans.length()!=n+2) printf("NO\n");else cout<<"YES\n"<<ans<<endl;return 0;
}
/*
需判if(ans.length()!=n+2)的样例
4
aba
bab
cdc
dcd
*/



E. Arthur and Brackets

time limit per test2 seconds
memory limit per test128 megabytes
inputstandard input
outputstandard output
Notice that the memory limit is non-standard.
Recently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2n. Unlike Arthur, Sasha understood the topic very badly, and broke Arthur's favorite correct bracket sequence just to spite him.


All Arthur remembers about his favorite sequence is for each opening parenthesis ('(') the approximate distance to the corresponding closing one (')'). For the i-th opening bracket he remembers the segment [li,?ri], containing the distance to the corresponding closing bracket.


Formally speaking, for the i-th opening bracket (in order from left to right) we know that the difference of its position and the position of the corresponding closing bracket belongs to the segment [li,?ri].


Help Arthur restore his favorite correct bracket sequence!


Input
The first line contains integer n (1?≤?n?≤?600), the number of opening brackets in Arthur's favorite correct bracket sequence.


Next n lines contain numbers li and ri (1?≤?li?≤?ri?<?2n), representing the segment where lies the distance from the i-th opening bracket and the corresponding closing one.


The descriptions of the segments are given in the order in which the opening brackets occur in Arthur's favorite sequence if we list them from left to right.


Output
If it is possible to restore the correct bracket sequence by the given data, print any possible choice.


If Arthur got something wrong, and there are no sequences corresponding to the given information, print a single line "IMPOSSIBLE" (without the quotes).


Sample test(s)
input
4
1 1
1 1
1 1
1 1
output
()()()()
input
3
5 5
3 3
1 1
output
((()))
input
3
5 5
3 3
2 2
output
IMPOSSIBLE
input
3
2 3
1 4
1 4
output
(())()

贪心版:(不明的话拿样例试试就非常清楚了)

#include <cstdio>
#include <stack>
using namespace std;
#define mm 700
int n, L[mm], R[mm],i;
char s[mm * 2];
int main()
{scanf("%d", &n);for(i = 0; i < n; ++i) scanf("%d%d", &L[i], &R[i]);int rear = 0;  	//当前字符串的末尾下标stack<pair<int, int> > st;for(i = 0; i < n; ++i){st.push(make_pair(L[i]+rear, R[i]+rear));s[rear++] = '(';while(!st.empty() && st.top().first <= rear && rear <= st.top().second){s[rear++] = ')';st.pop();}if(!st.empty() && rear > st.top().second) break;//超过栈顶区间范围,即配不上对了}if(!st.empty())puts("IMPOSSIBLE");else puts(s);return 0;
}



这篇关于Codeforces Round #288 (Div. 2)(稍看即懂,不解释)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1123910

相关文章

wolfSSL参数设置或配置项解释

1. wolfCrypt Only 解释:wolfCrypt是一个开源的、轻量级的、可移植的加密库,支持多种加密算法和协议。选择“wolfCrypt Only”意味着系统或应用将仅使用wolfCrypt库进行加密操作,而不依赖其他加密库。 2. DTLS Support 解释:DTLS(Datagram Transport Layer Security)是一种基于UDP的安全协议,提供类似于

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

Codeforces Round #113 (Div. 2) B 判断多边形是否在凸包内

题目点击打开链接 凸多边形A, 多边形B, 判断B是否严格在A内。  注意AB有重点 。  将A,B上的点合在一起求凸包,如果凸包上的点是B的某个点,则B肯定不在A内。 或者说B上的某点在凸包的边上则也说明B不严格在A里面。 这个处理有个巧妙的方法,只需在求凸包的时候, <=  改成< 也就是说凸包一条边上的所有点都重复点都记录在凸包里面了。 另外不能去重点。 int

Codeforces 482B 线段树

求是否存在这样的n个数; m次操作,每次操作就是三个数 l ,r,val          a[l] & a[l+1] &......&a[r] = val 就是区间l---r上的与的值为val 。 也就是意味着区间[L , R] 每个数要执行 | val 操作  最后判断  a[l] & a[l+1] &......&a[r] 是否= val import ja

CSS实现DIV三角形

本文内容收集来自网络 #triangle-up {width: 0;height: 0;border-left: 50px solid transparent;border-right: 50px solid transparent;border-bottom: 100px solid red;} #triangle-down {width: 0;height: 0;bor

嵌入式技术的核心技术有哪些?请详细列举并解释每项技术的主要功能和应用场景。

嵌入式技术的核心技术包括处理器技术、IC技术和设计/验证技术。 1. 处理器技术    通用处理器:这类处理器适用于不同类型的应用,其主要特征是存储程序和通用的数据路径,使其能够处理各种计算任务。例如,在智能家居中,通用处理器可以用于控制和管理家庭设备,如灯光、空调和安全系统。    单用途处理器:这些处理器执行特定程序,如JPEG编解码器,专门用于视频信息的压缩或解压。在数字相机中,单用途

请解释Java Web应用中的前后端分离是什么?它有哪些好处?什么是Java Web中的Servlet过滤器?它有什么作用?

请解释Java Web应用中的前后端分离是什么?它有哪些好处? Java Web应用中的前后端分离 在Java Web应用中,前后端分离是一种开发模式,它将传统Web开发中紧密耦合的前端(用户界面)和后端(服务器端逻辑)代码进行分离,使得它们能够独立开发、测试、部署和维护。在这种模式下,前端通常通过HTTP请求与后端进行数据交换,后端则负责业务逻辑处理、数据库交互以及向前端提供RESTful

OpenStack:Glance共享与上传、Nova操作选项解释、Cinder操作技巧

目录 Glance member task Nova lock shelve rescue Cinder manage local-attach transfer backup-export 总结 原作者:int32bit,参考内容 从2013年开始折腾OpenStack也有好几年的时间了。在使用过程中,我发现有很多很有用的操作,但是却很少被提及。这里我暂不直接