标签:style blog http color os io ar strong for
【A】
As an artist, Bob usually need to travel around the world. He made a lot of sketch of scenery on his journey. A famous spot he have visited recently is the Himalayas. The Himalayas is a mountain range in South Asia separating the plains of the Indian subcontinent from the Qinghai-Tibet Plateau. The Himalayas include over a hundred mountains exceeding 7,200 meters in elevation.
One day, Bob came up with an strange idea. He wanted to know the number of mountain peaks in his paintings. As his best friend, he turned to you for help. You are given a list of N height sampling values Hi. You should determine how many peaks are there. For all i which satisfies 2 <= i <= N - 1, Hi is defined as a peak if and only if Hi-1 < Hi > Hi+1.
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains one integer N (1 <= N <= 50). The next line contains N integers Hi (1 <= Hi <= 8844). It is guaranteed that any two adjacent height sampling values will be different.
For each test case, output the number of peaks.
2 9 1 3 2 4 6 3 2 3 1 5 1 2 3 4 5
3 0
【分析】
水出来~~~!!!
【C】
Edward is a rich man. He owns a large factory for health drink production. As a matter of course, there is a large warehouse in the factory.
To ensure the safety of drinks, Edward hired a security man to patrol the warehouse. The warehouse has N piles of drinks and M passageways connected them (warehouse is not big enough). When the evening comes, the security man will start to patrol the warehouse following a path to check all piles of drinks.
Unfortunately, Edward is a suspicious man, so he sets sensors on K piles of the drinks. When the security man comes to check the drinks, the sensor will record a message. Because of the memory limit, the sensors can only record for the first time of the security man‘s visit.
After a peaceful evening, Edward gathered all messages ordered by recording time. He wants to know whether is possible that the security man has checked all piles of drinks. Can you help him?
The security man may start to patrol at any piles of drinks. It is guaranteed that the sensors work properly. However, Edward thinks the security man may not works as expected. For example, he may digs through walls, climb over piles, use some black magic to teleport to anywhere and so on.
There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:
The first line contains three integers N (1 <= N <= 100000), M (1 <= M <= 200000) and K (1 <= K <= N).
The next line contains K distinct integers indicating the indexes of piles (1-based) that have sensors installed. The following M lines, each line contains two integers Ai and Bi (1 <= Ai, Bi <= N) which indicates a bidirectional passageway connects piles Ai and Bi.
Then, there is an integer L (1 <= L <= K) indicating the number of messages gathered from all sensors. The next line contains L distinct integers. These are the indexes of piles where the messages came from (each is among the K integers above), ordered by recording time.
For each test case, output "Yes" if the security man worked normally and has checked all piles of drinks, or "No" if not.
2 5 5 3 1 2 4 1 2 2 3 3 1 1 4 4 5 3 4 2 1 5 5 3 1 2 4 1 2 2 3 3 1 1 4 4 5 3 4 1 2
No Yes
【分析】
1.floodfill染色:
当时看到这道题想到的只有暴力DFS,写出来之后发现由于floodfill染色的性质,每个点只是访问一次就够了,效率还是很优的,不算暴力求解。
对每一个结点设置四种标记:无标记、已访问、不可访问、能够访问;
普通点在到达之前无标记,到达之后标记为已访问;传感器结点在到达之前标记为不可访问,到达之后标记为能够访问,搜过之后标记为已访问;
一、直接搜索L个传感器的序列,首先将所有拥有传感器的序列全部标记为不可访问;
二、从第一个开始,扩展遍历所有能到达的点,遍历时的点有两种状态:无标记(普通点)和不可/能够访问(带有传感器的点)。无标记点可以直接改为已访问,不可访问的点则标记为能够访问。遍历完之后将该传感器点标为已访问;
三、判断下一个传感器点的状况是不是能够访问,若是则表示可以从之前的传感器点不经过任何序列后面的点而到达,若标记是不可访问则表示不可能从之前的传感器点到达这里,那就直接输出NO了。
四、之后重复二、三过程,直到搜完所有L个点,判断整张图的连通性,即是不是所有点都能到达。
对于K和L,个人觉得描述的最后一句是有用的,就是L只会小于等于K,不一定要等于K。然后第一次没有加这个特判,结果WA了......加上之后AC,-_-////真的是我想多了吗
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 6 using namespace std; 7 8 typedef struct nod 9 { 10 int x,y; 11 } node; 12 node a[400010]; 13 int start[100010],num[100010]; 14 unsigned short flag[100010]; 15 16 int sen[100010]; 17 18 bool op(node a,node b) 19 { 20 if (a.x==b.x) return a.y<b.y; 21 else return a.x<b.x; 22 } 23 24 void dfs(int s) 25 { 26 flag[s]=3; 27 for (int i=0;i<num[s];i++) 28 { 29 int next=a[start[s]+i].y; 30 if (flag[next]==0) dfs(next); 31 else if (flag[next]==1) flag[next]=2; 32 } 33 } 34 35 int main() 36 { 37 int t; 38 scanf("%d",&t); 39 for (int tt=1;tt<=t;tt++) 40 { 41 int n,m,k; 42 scanf("%d%d%d",&n,&m,&k); 43 for (int i=1;i<=k;i++) scanf("%d",&sen[i]); 44 for (int i=1;i<=m;i++) 45 { 46 int x,y; 47 scanf("%d%d",&x,&y); 48 a[i*2].x=x; 49 a[i*2].y=y; 50 a[i*2-1].x=y; 51 a[i*2-1].y=x; 52 } 53 54 int l; 55 scanf("%d",&l); 56 57 memset(flag,0,sizeof(flag)); 58 for (int i=1;i<=l;i++) 59 { 60 scanf("%d",&sen[i]); 61 flag[sen[i]]=1; 62 } 63 64 if (l<k) 65 { 66 printf("No\n"); 67 continue; 68 } 69 70 m*=2; 71 memset(start,0,sizeof(start)); 72 memset(num,0,sizeof(num)); 73 sort(&a[1],&a[m+1],op); 74 int o=0; 75 for (int i=1;i<=m;i++) 76 { 77 if (o!=a[i].x) 78 { 79 o=a[i].x; 80 start[o]=i; 81 } 82 num[o]++; 83 } 84 85 flag[sen[1]]=2; 86 bool outp=true; 87 for (int i=1;i<=l;i++) 88 if (flag[sen[i]]==2) dfs(sen[i]); 89 else 90 { 91 outp=false; 92 break; 93 } 94 95 if (outp) 96 for (int i=1;i<=n;i++) 97 if (flag[i]!=3) 98 { 99 outp=false; 100 break; 101 } 102 103 if (outp) printf("Yes\n"); 104 else printf("No\n"); 105 } 106 107 return 0; 108 }
2.并查集
大体思路与上面类似,把1中的染色部分改成扩展一个可以任意到达的无限集即可。
【J】
Poetry is a form of literature that uses aesthetic and rhythmic qualities of language. There are many famous poets in the contemporary era. It is said that a few ACM-ICPC contestants can even write poetic code. Some poems has a strict rhyme scheme like "ABABA" or "ABABCAB". For example, "niconiconi" is composed of a rhyme scheme "ABABA" with A = "ni" and B = "co".
More technically, we call a poem pretty if it can be decomposed into one of the following rhyme scheme: "ABABA" or "ABABCAB". The symbol A, B and C are different continuous non-empty substrings of the poem. By the way, punctuation characters should be ignored when considering the rhyme scheme.
You are given a line of poem, please determine whether it is pretty or not.
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
There is a line of poem S (1 <= length(S) <= 50). S will only contains alphabet characters or punctuation characters.
For each test case, output "Yes" if the poem is pretty, or "No" if not.
3 niconiconi~ pettan,pettan,tsurupettan wafuwafu
Yes Yes No
【分析】
由于本题数据量最大只有50个字符,可以直接模拟枚举。
首先枚举AB,满足AB匹配之后,再判断AB长度的三倍与总长度之间的关系,分类讨论。
算法就是这么个算法,但是实现起来超容易出错......
附上一组处理得比较全面的测试数据
1 8 2 xyxyxxy 3 xyxyyxy 4 xxxxyxx 5 xxxxx 6 xyxyx 7 xxxxxxxx 8 xxxxxxxxxxxxx 9 xyzzxyzxyzzxyzxyzxyzzxyz
The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
标签:style blog http color os io ar strong for
原文地址:http://www.cnblogs.com/jcf94/p/3961201.html