A - 1 CodeForces - 711A
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of rows of seats in the bus.
Then, n lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals ‘|’) and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to ‘O’ or to ‘X’. ‘O’ denotes an empty seat, ‘X’ denotes an occupied seat. See the sample cases for more details.
Output
If it is possible for Chris and ZS to sit at neighbouring empty seats, print “YES” (without quotes) in the first line. In the next n lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters ‘+’. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to ‘O’ in the input and to ‘+’ in the output).
If there is no pair of seats for Chris and ZS, print “NO” (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Examples
Input
6
OO|OX
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
Output
YES
++|OX
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX
Input
4
XO|OX
XO|XX
OX|OX
XX|OX
Output
NO
Input
5
XX|XX
XX|XX
XO|OX
XO|OO
OX|XO
Output
YES
XX|XX
XX|XX
XO|OX
XO|++
OX|XO
一开始没看清楚题意,不行的话只输出NO;是要从一堆字符中找出连续的OO,并把它标注为++;
方法:左一对,右一对检测。注意ok了之后就可以break;了,关于错误的标记可以放到最后,前面检测完了再标注。
本人写得十分简单,dalao轻喷。
#include<iostream>
using namespace std;
int main()
{
int n, jud=0; char a[1005][5];
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3] >> a[i][4];
}
for (int i = 0; i < n; i++)
{
if (a[i][0] == 'O'&&a[i][1] == 'O')
{
jud = 1;
a[i][0] = '+'; a[i][1] = '+'; break;
}
else
if (a[i][3] == 'O'&&a[i][4] == 'O')
{
jud = 1;
a[i][3] = '+'; a[i][4] = '+';
break;
}
jud = 0;
}
if (jud == 1)
{
cout << "YES" << endl;
for (int i = 0; i < n; i++)
{
cout << a[i][0] << a[i][1] << a[i][2] << a[i][3] << a[i][4] << endl;
}
}
else
cout << "NO" << endl;
return 0;
}
C - 3 HDU - 1422(dp)
C原题链接
世界杯结束了,意大利人连本带利的收回了法国人6年前欠他们的债,捧起了大力神杯,成就了4星意大利.
世界杯虽然结束了,但是这界世界杯给我们还是留下许多值得回忆的东西.比如我们听到了黄名嘴的3分钟激情解说,我们懂得了原来可以向同一个人出示3张黄牌,我们还看到了齐达内的头不仅能顶球还能顶人…………
介于有这么多的精彩,xhd决定重温德国世界杯,当然只是去各个承办世界杯比赛的城市走走看看.但是这需要一大比钱,幸运的是xhd对世界杯的热爱之情打动了德国世界杯组委会,他们将提供xhd在中国杭州和德国任意世界杯承办城市的往返机票,并说服了这些城市在xhd到达这座城市时为他提供一笔生活费以便他在那里参观时用,当参观完时剩余的钱也将留给xhd,但当生活费不够时他们将强行结束xhd的这次德国之行,除了这个,他们还有一个条件,xhd只能根据他们所给的路线参观.比如有3座城市a,b,c,他们给定了a-b-c-a的路线,那么xhd只有3种参观顺序abc,bca,cab.由于各个城市所提供的生活费和在那里的花费都不同,这使xhd很头痛,还好我们事先知道了这笔生活费和花费.请问xhd最多能顺利参观几座城市?
Input
每组输入数据分两行,第一行是一个正整数n(1<=n<=100000),表示有n座城市.接下来的一行按照给定的路线顺序的输出这n个城市的生活费和花费,w1,l1,w2,l2,……,wn,ln,其中wi,li分别表示第i个城市的生活费和花费,并且它们都是正整数.
Output
对应每组数据输出最多能参观的城市数.
Sample Input
3
3 2 3 4 2 2
3
3 2 3 4 2 3
Sample Output
3
2
本人的做法是:把所到的每个地方的各所剩的钱算出了,然后再找最长的总和非负的序列,把每个点能呆的天数算出来,再找最大。
需要注意的一点是,while (scanf_s("%d", &n) == 1)时,要等于1才行,表示输入成功,如果没有“==1”的话,自己跑倒没什么问题,但是oj上的话会TLE。
/*
miku saiko
*/
#include<iostream>
using namespace std;
int a[200010], ans[200010];
int main()
{
int n, i, t1, t2;
while (scanf_s("%d", &n) == 1)
{
for (i = 0; i<n; i++)
{
scanf_s("%d%d", &t1, &t2);
a[i] = a[i + n] = t1 - t2;//多的费用
ans[i] = ans[i + n] = 1;//初始记为一天
}
for (i = 1; i<2 * n; i++)
{
if (a[i - 1] >= 0 &&a[i] + a[i - 1] >= 0 )//开始第一天大于零才能出发
{
a[i] = a[i] + a[i - 1];
ans[i] += ans[i - 1];
if (ans[i] == n) break;//可以完整地游一趟
}
}
int Max = 0;
for (i = 0; i<2 * n; i++)//寻历一遍找最大
if (Max<ans[i])
Max = ans[i];
printf("%d\n", Max);
}
return 0;
}