[2016 Changzhou No. 1 summer camp Day2], 2016 Changzhou day2
W to learn mathematics
[Problem description]
In order to test the mathematical level of the small W, the fruit gave the small w n points and asked him the number of triangles which the N points can constitute.
[Input format]
The first line is an integer N, indicating the number of points.
In the next N rows, two non-negative integers X and Y in each line represent the coordinates of a point.
[Output format]
A non-negative integer represents the number of triangles.
[Input and output sample]
Tri. in
5
0 0
1 0
2 0
0 1
1 1
Tri. out
9
[Data scale]
For 20% of data: N = 3
For another 40% of data, make sure that any three points are not in the same line.
For 100% of data: N <= 100, ensure that any two points do not overlap, coordinates <= 10000
Question
The brute-force enumeration uses the slope or cross product to determine if the data is collocated. Just count the answer.
#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int n,ans;int x[105],y[105];int main(){ int i,j,k; freopen("tri.in","r",stdin); freopen("tri.out","w",stdout); scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]); for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) for(k=j+1;k<=n;k++) if((y[k]-y[j])*(x[j]-x[i])!=(y[j]-y[i])*(x[k]-x[j])) ans++; printf("%d",ans); fclose(stdin); fclose(stdout); return 0;}
W learns English
[Problem description]
To test the English proficiency of small M, Mr. R asked small M to write English compositions, while small M handed over the compositions to small W. However, Mr. R sums up the habit of writing a text, that is, some key strings. If several key strings appear in an essay, he thinks this is written by W. Note that W may write multiple compositions.
[Input format]
The first line is an integer N, indicating the number of Key Strings. N <= 100.
In the next N rows, each row contains a string of no more than 100 characters.
There are several segments of text, each ending with $.
Because the number of people who write the essay is too crazy, each essay can contain a maximum of 1350000 characters, but the number of compositions cannot exceed 10.
[Output format]
Each text segment corresponds to a line of output. 'Yes' indicates a small W essay, and 'no' indicates No.
Note the case sensitivity.
[Input and output sample]
Letter. in
3 I
Love
M
Ilovem $
Lovem $
Letter. out
Yes
No
[Data scale]
For 50% of data: N <= 7
Question
AC automatic machine
I would like to thank TonyFang for sharing the materials on AC automatic machines.
About Fail pointer http://www.acyume.com/archives/19
About AC automatic machine http://blog.csdn.net/jw72jw/article/details/6843700
#include<iostream>#include<cstdlib>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespace std; int n,x,siz;int len[110],fail[2000005],last[2000005],cnt[2000005],ch[2000005][27];char ask[2000005],str[1005];bool val[2000005];queue<int> q; void ACinsert() { int i,p,len,c; p=0; len=strlen(str); for(i=0;i<len;i++) { c=str[i]-'a'; if(!ch[p][c]) ch[p][c]=++siz; p=ch[p][c]; } val[p]=true;} inline void ACgetfail() { int i,j,c,p,v,now; fail[0]=0; for(c=0;c<26;c++) { p=ch[0][c]; if(p) { fail[p]=last[p]=0; q.push(p); } } while(!q.empty()) { now=q.front(); q.pop(); for(c=0; c<26; ++c) { p=ch[now][c]; if(!p) continue; q.push(p); v=fail[now]; while(v&&!ch[v][c]) v=fail[v]; fail[p]=ch[v][c]; last[p]=val[fail[p]]?fail[p]:last[fail[p]]; } }} void ACadd(int x) { for(;x;x=last[x]) cnt[x]=1;} void ACfind() { int i,j,p,len,c; p=0; len=strlen(ask); memset(cnt,0,sizeof(cnt)); for(i=0;i<len-1;i++) { c=ask[i]-'a'; while(p&&!ch[p][c]) p=fail[p]; p=ch[p][c]; if(val[p]) ACadd(p); else if(last[p]) ACadd(last[p]); }} int main() { int i,j; bool flag; freopen("letter.in","r",stdin); freopen("letter.out","w",stdout); scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%s",str); ACinsert(); } ACgetfail(); while(~scanf("%s",ask)) { ACfind(); flag=false; for(i=1;i<=siz;i++) if(val[i]!=0) if(cnt[i]==0) { flag=true; break; } if(flag) puts("No"); else puts("Yes"); } fclose(stdin); fclose(stdout); return 0;}
Knowledge of physics
[Problem description]
To test the physical level of small W, Mr. X places N mirrors in the two-dimensional coordinate system (the absolute value of mirror coordinates cannot exceed M), and the mirrors are all 45 ° angle with the coordinate axis, therefore, there are two types: "/" and "\". There is no mirror at the origin. At any point, there is only one mirror at most. Both sides of the mirror can be reflected, but the middle is not transparent. For example, for a "/" type mirror, the light injected in the lower direction is reflected to the right direction, the light injected from the left direction is reflected to the top.
Now there is a line of light from the origin along the square of the X axis, find the location after the T journey.
[Input format]
The first row has three integers, N, M, and T.
Lines 2nd to N + 1, each line has two integers Xi, Yi, representing mirror coordinates. One character Si represents the mirror type.
[Output format]
A line of two integers represents the coordinates after the T journey.
[Input and output sample]
Mir. in
5 2 8
0 1 \
0 2/
1 0/
1 1 \
1 2 \
Mir. out
3 1
[Data scale]
For 20% of data: N = 1
For 40% of data: N <= 1000
For 40% of data: M <= 1000
For 40% of data: T <= 1000000
Question
Prepare each mirror to reflect the number of the mirror that will arrive at the light line in four directions, and then simulate and determine the ring.