# Codeforces #208 div2前两题及思维风暴

A. Dima and Continuous Line
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.

The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any).

Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.

Input

The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.

Output

In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).

Sample test(s)
input
4
0 10 5 15

output
yes

input
4
0 15 5 10

output
no

Note

The first test from the statement is on the picture to the left, the second test is on the picture to the right.

AC代码：

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int a[1005];

int main()
{
int n,i,j;
while(cin>>n)
{
for(i=0;i<n;i++)
cin>>a[i];
int flag =0,mi1,mi2,ma1,ma2;
for(i=0;i<n-1;i++)
{
mi1=min(a[i],a[i+1]);
ma1=max(a[i],a[i+1]);  //第一条线mi1-ma1 第二条线mi2-ma2
for(j=i+2;j<n-1;j++)
{
mi2=min(a[j],a[j+1]);
ma2=max(a[j],a[j+1]);
if((mi2>mi1&&mi2<ma1&&ma2>ma1)||(mi2<mi1&&ma2>mi1&&ma2<ma1))  //相交
{
flag=1;
break;
}
}
if(flag) break;
}

if(flag) puts("yes");
else puts("no");
}
return 0;
}

/*
7
4 6 7 1 2 3 5
*/


B. Dima and Text Messages
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.

Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (<) and the digit three (3). After applying the code, a test message looks like that: <3word1<3word2<3 ... wordn<3.

Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message.

Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above.

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of words in Dima's message. Next n lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.

The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less.

Output

In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise.

Sample test(s)
input
3
i
love
you
<3i<3love<23you<3

output
yes

input
7
i
am
not
main
in
the
family
<3i<>3am<3the<3<main<3in<3the<3><3family<3

output
no

Note

Please note that Dima got a good old kick in the pants for the second sample from the statement.

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

string a[100005];
string p;

int main()
{
int n,i,j;
while(cin>>n)
{
for(i=0;i<n;i++)
cin>>a[i];
cin>>p;
int flag=0;
int fla=0;
int s=0,t=0;
for(i=0;i<p.length();i++)
{
if(s==n)
{
fla=1;
break;
}
if(flag==0)  //先匹配<
{
if(p[i]=='<')
flag=1;
}
else if(flag==1)  //匹配3
{
if(p[i]=='3')
flag=2;
}
else
{
if(p[i]==a[s][t]&&t==a[s].length()-1)
{
s++;
t=0;
flag=0;   //匹配一个串后需要重新匹配<3
}
else if(p[i]==a[s][t])
{
t++;
}
}
}

//cout<<s<<" "<<i<<endl;
flag=0;
if(fla)   //匹配最后的<3
{
for(j=i;j<p.length();)
{
if(flag==0)  //匹配<
{
if(p[j]=='<')
flag=1;
j++;
}
else if(flag==1)  //匹配3
{
if(p[j]=='3')
{
fla=2;
break;
}
j++;
}
}
}

if(fla==2) puts("yes");
else puts("no");
}
return 0;
}

/*
3
i
love
you
<3i<3lo<3ve<3y<<<<<<<ou3<3
1
a
<3a<2
2
a
i
<3ai<3
*/

//46MS


#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

string a;
string p;
string tmp;

int main()
{
int n,i,j;
while(cin>>n)
{
a="<3";  //先加在最前面
for(i=0;i<n;i++)
{
cin>>tmp;
a=a+tmp;
a+="<3";  //每一串后面都加一个<3
}

//现在a串是最短长度的解
cin>>p;
int t=0,len=a.length();
for(i=0;i<p.length();i++)
{
if(t==len) break;
if(p[i]==a[t])
t++;
}
if(t==len) puts("yes");
else puts("no");
}
return 0;
}

//1684 ms

think........

还有一个题目是关于公倍数的，求解%3=a,%5=b,%7=c，这样的最小的正整数t，我们假设t=(5*7*s1)*a+(3*7*s2)*b+(3*5*s3)*c.我们只需要保证5*7*s1%3=1即可，因此s1取2，依次s2=1,s3=1。我们可以将他的一个解找到，然后+lcm(3,5,7)*k就是他的通解了，就可以求解了。

10-18 729

08-02 246
11-26 1483
03-09 643
03-11 783
04-16 879
04-04 927
10-06 583
02-02 676
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie