Codeforces Round #363 (Div. 2)
来源:互联网 发布:软件测试 培训 编辑:程序博客网 时间:2024/06/10 18:39
A:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line.n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of thei-th particle and its position in the collider at the same time. All coordinates of particle positions areeven integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles.
The second line contains n symbols "L" and "R". If thei-th symbol equals "L", then thei-th particle will move to the left, otherwise thei-th symbol equals "R" and thei-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
4RLRL2 4 6 10
1
3LLR40 50 60
-1
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and2 will simultaneously be at the same point with the coordinate3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
题意:
n个人,每个人的速度相同,给出方向和初始位置问经过几秒有人相遇,没有输出-1.
题解:
因为每个人的速度相同,所以能够相遇的情况只能是前一个人向右(R)走,后一个人向左(L)走。判断这种情况即可。
代码:
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cmath>#include <queue>#include <stack>#define mem(a) memset(a, 0, sizeof(a))#define eps 1e-5#define M 200005#define inf 1000000007using namespace std;char a[M];int b[M];int main(){ int t; cin>>t; int mx=inf; scanf("%s",a); for(int i=0;i<t;i++) scanf("%d",&b[i]); bool flag=false; for(int i=0;i<t;i++) if(a[i]=='R') flag=true; else { if(flag) mx=min(mx,(b[i]-b[i-1])/2); flag=false; } if(mx!=inf) cout<<mx<<endl; else cout<<-1<<endl; }B:
You are given a description of a depot. It is a rectangular checkered field ofn × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the rowx and all walls in the column y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggeringexactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
The first line contains two positive integers n andm (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.
The next n lines contain m symbols "." and "*" each — the description of the field.j-th symbol in i-th of them stands for cell(i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.
3 4.*.......*..
YES1 2
3 3..*.*.*..
NO
6 5..*....*..*****..*....*....*..
YES3 3
题解:
首先统计每行每列和总的墙个数,遍历判断,如果该位置放炸弹可以炸掉所有的墙,输出。注意,当该位置本身是墙时,行列和会多算一次。
代码:
#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cmath>#include <queue>#include <stack>#define mem(a) memset(a, 0, sizeof(a))#define eps 1e-5#define M 200005#define inf 1000000007using namespace std;char ap[1001][1001];int r[1001];int l[1001];int x,y,k;int main(){ scanf("%d%d",&x,&y); mem(r); mem(l); k=0; for(int i=1; i<=x; i++) { scanf("%s",ap[i]+1); } for(int i=1; i<=x; i++) { for(int j=1; j<=y; j++) { if(ap[i][j]=='*') { r[i]++; l[j]++; k++; } } } for(int i=1; i<=x; i++) { for(int j=1; j<=y; j++) { if(r[i]+l[j]+(ap[i][j]=='*'?-1:0)==k) { puts("YES"); printf("%d %d\n",i,j); return 0; } } } puts("NO"); return 0;}C:
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of thisn days: whether that gym opened and whether a contest was carried out in the Internet on that day. For thei-th day there are four options:
- on this day the gym is closed and the contest is not carried out;
- on this day the gym is closed and the contest is carried out;
- on this day the gym is open and the contest is not carried out;
- on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has —he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:
- ai equals 0, if on thei-th day of vacations the gym is closed and the contest is not carried out;
- ai equals 1, if on thei-th day of vacations the gym is closed, but the contest is carried out;
- ai equals 2, if on thei-th day of vacations the gym is open and the contest is not carried out;
- ai equals 3, if on thei-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days,
- to write the contest on any two consecutive days.
41 3 2 0
2
71 3 3 2 1 2 3
0
22 2
1
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
n天,每天可以比赛,锻炼,休息,但是相邻两天不可做同样事情(休息除外),给你n天的状态(0:体育场和比赛都没有。1:有比赛没体育场。2:有体育场没比赛。3:有体育场,有比赛。)问至少可以休息几天。
题解:
一看就是dp.
dp[i][j]表示第i天作J这件事(j:0代表休息,1代表比赛,2代表锻炼)休息了几天。
状态转移方程:
</pre><pre name="code" class="cpp"> if(s[i]==0)( { dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; } else if(s[i]==1) { dp[i][1]=min(dp[i-1][1]+1,min(dp[i-1][0],dp[i-1][2])); dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; } else if(s[i]==2) { dp[i][2]=min(dp[i-1][2]+1,min(dp[i-1][0],dp[i-1][1])); dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; } else { dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; dp[i][1]=min(dp[i-1][1]+1,min(dp[i-1][0],dp[i-1][2])); dp[i][2]=min(dp[i-1][2]+1,min(dp[i-1][0],dp[i-1][1]));代码:
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <cmath> #include <queue> #include <stack> #define mem(a) memset(a, 0, sizeof(a)) #define eps 1e-5 #define M 200005 #define inf 1000000007 using namespace std; int s[105]; int dp[105][3]; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>s[i]; for(int j=0;j<3;j++) dp[i][j]=inf; } for(int i=1;i<=n;i++) { if(s[i]==0) { dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; } else if(s[i]==1) { dp[i][1]=min(dp[i-1][1]+1,min(dp[i-1][0],dp[i-1][2])); dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; } else if(s[i]==2) { dp[i][2]=min(dp[i-1][2]+1,min(dp[i-1][0],dp[i-1][1])); dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; } else { dp[i][0]=min(min(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+1; dp[i][1]=min(dp[i-1][1]+1,min(dp[i-1][0],dp[i-1][2])); dp[i][2]=min(dp[i-1][2]+1,min(dp[i-1][0],dp[i-1][1])); } } printf("%d\n",min(dp[n][0],min(dp[n][1],dp[n][2]))); return 0; }
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2)
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) [C] Vacations
- Codeforces Round #363 (Div. 2) C. Vacations
- Codeforces Round #363 (Div. 2) 题解报告
- Codeforces Round #363 (Div. 2)-C--贪心
- Codeforces Round #363 (Div. 2)--B
- Codeforces Round #363 (Div. 2) 题解
- Codeforces Round #363 (Div. 2) B 暴力
- Codeforces Round #363 (Div. 2) C dp
- 最新eclipse整合Struts2.3.29+Hibernate5.2.1+Spring4.3.1(三)Struts+Hibernate+spring篇
- IOS开发中实现whatsapp和Facebook分享过程的总结
- 神经网络的严格矩阵求导
- 经典排序算法 集锦
- 查看数据库支持哪些存储类型
- Codeforces Round #363 (Div. 2)
- android性能优化
- MySQL5.7半同步复制技术
- AndroidStudio安装步骤
- ListView优化方案
- APK保护技术——保护应用、游戏APP不被破解
- confluent 版本比较 3.0.0 vs 2.0.0
- 在java 用xml模板通过freemarker生成word文档
- 设计一个带MIN的栈,要求出栈,入栈,返回最小值的时间复杂度为O(1)