昨晚原本准备在宿舍打cf的,结果吵吵闹闹的,也没打成,头也晕晕的,当时看了只看了第一个题,越想越麻烦,最后竟然陷入了误区,半小时也没解,虽然注册了,一发也没交。。。

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.

题目意思很好懂,就看你怎么去建立模型,简化计算。早上起床灵光一闪。如果要是两线相交的话,必然存在公共区域。可以直接枚举任意的两条线,时间复杂度为O(10^6)。具体实现见代码。

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-ma2for(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.

这个题目如果看懂的话,相当easy,关键是要看懂。。当时第一题没搞出来就直接没看了。前面给你n个串,在每个串前面加上<3后面加上>3链接在一起。最后在链接好的串里插入任意字段。再给你一个串,问满足条件否?

开始原先想的就是先比较<3然后跟串一个一个挨着比较,每比较完一个,就再匹配一个<3。具体实现见代码。最后还需要匹配一个<3.

代码:

#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

后来仔细想可以先把满足条件最简单的串构造出来,再匹配。估计是用了string +,时间有点多。

代码:

#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

然后算法设计老师讲的一个题目蛮有意思的,给你两根长短不同,粗细不均匀的绳子,我们仅仅知道每根绳子烧完需要1h,问怎么才能使得两根绳子都烧完,且刚好用时45min.

think........

用火机先点燃一根绳子的两头和另一根绳子的一头。这样用时30min,之后将剩下的绳子的另一头点燃。

还有一个题目是关于公倍数的,求解%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就是他的通解了,就可以求解了。

Codeforces #208 div2前两题及思维风暴相关推荐

  1. BestCoder Round #4 前两题 hdu 4931 4932

    第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include< ...

  2. 计算机二级考试题有之前的吗,国家计算机二级上机做对前两题为什么过不了

    你是考C语言还是考VB呀,我们学校好像考C语言吧! 一.对于笔试: 二级VB考试的考题内容很细,没有复杂的算法题,最多只是一些看起来复杂(其实很有规律)的循环题.那么,我们要做的是: 1:按照大纲读懂 ...

  3. 第十二届全国大学生信息安全竞赛-RE部分WP(目前前两题,待更)

    RE2-bbvvmm 分析 拖入IDA,题目流程基本呈现,直接看到最后的check 这里即,用户名和密码都在此验证.密码最终得到的结果在ptr+25,而用户名得到的结果,像是经过一系列字符处理,最终与 ...

  4. 【 2013华为杯编程大赛成都第三组前两题试题及答案】

    2013-09-12 16:41:24 题目描述 某省会城市街道纵横交错,为了监控路灯的运行状况,每条街道使用一个数字字符串标识该街道上所有路灯的运行状况. 假设路灯只有如下3种状态(分别用数字0, ...

  5. 微众银行4.20笔试前两题(均AC)

    第一题:氪金升级:第一行输入一个数字n,n表示游戏的总轮次.第二行输入玩家每一轮造成的伤害值,第三行输入敌人每一轮造成的伤害值.玩家必须所有轮次里,在每一轮结束时,造成伤害的总和大于敌方造成伤害的总和 ...

  6. Codeforces Global Round 1 E 题【思维】

    传送门 题意: 给定n个数的两个数组, c数组和t数组, 每次可以选择一个i(1 < i < n) 使得c[i] = c[i+1] + c[i-1] - c[i]; 问能不能再进行若干次这 ...

  7. 2018 360校招笔试(前两题)

    n个点,找出可以包含所有点的一个最小矩形的面积 很简单,直接 x轴y轴 分别记录一个最大值最小值,这时可以获得一个最小长方形,在长宽里面取个最大值就得到了正方形的边长,算个平方就出来了 PS. 这道题 ...

  8. 合肥市2021信息学小学组试卷+代码前两题

    废话不多说,直接开始! 想下载文件的移步最后 体质指数(bmi) 题目描述 体重和身高是人体最基本的数值,BMI 指数是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是 ...

  9. codeforces round div2,3周赛补题计划(从开学到期末)

    1. 本学期场次 从2020.09.19-2021.01.18,一共18周. 题号 场次 日期 备注 1475 Codeforces Round #697 (Div. 3) 1.25 1474 Cod ...

最新文章

  1. java 函数内部类_java 内部类详解 转
  2. stm32 USB CDC 不接电脑无程序一直在USB中断问题
  3. pandas库简单入门
  4. 【网络安全】文件上传绕过思路总结
  5. 一步步实现:JPA的基本增删改查CRUD(jpa基于hibernate)
  6. 新海诚没有参与制作的作品_新海诚作品不出真人版,其实都是因为这!
  7. 文本分类模型_文本分类模型之TextCNN
  8. 找出矩阵中绝对值最大的元素及其位置_线性代数之——矩阵范数和条件数
  9. 什么是javax.ws.rs.core.context? [第5部分]
  10. 高通首次演示基于3GPP的5G新空口连接 有望成为全球标准
  11. 2021年了,Transformer有可能替代CNN吗?未来有哪些研究方向?
  12. 用户体验的13条金科玉律
  13. python:使用split以.划分句子、对列表进行切片
  14. python时间序列库_python Pandas库基础分析之时间序列的处理详解
  15. Chrome firefox ie等浏览器空格nbsp;宽度不一样
  16. python下opencv安装
  17. 学生通讯录管理系统的设计与实现
  18. 家庭WIFI路由器当交换机用
  19. JAVA之基数排序LSD顺序
  20. C#也能做机器学习?基于.NET的AI智能应用市场还是一片“处女地”

热门文章

  1. android手机通讯录没了,手机联系人不见了怎么恢复?手机通讯录误删如何恢复...
  2. 闽南歌歌词有一句电子计算机,抖音wow you can really dance下一句是什么歌 歌词全文...
  3. java字符串转数组的方法,写给正在求职的Java开发
  4. Linux编译gcc 11和binutils
  5. Messenger致命漏洞!黑客可窃听通话
  6. memset()函数的用法详解
  7. linux—wget安装redis
  8. SHT11源程序分享及51单片机仿真实现
  9. 电工 电路的暂态分析
  10. linux没有网卡驱动能pxe吗,PXE所需要的网卡驱动制作