problem A. Bad Horse
Test instructions: Give n relations, each relationship has two people, ask to divide these people into two groups, each group of people have no relationship.
Two-part graph dyeing can be. Relationship = side, man = point.
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < algorithm> #include <queue> #include <set> #include <map> #include <vector> #include < Cmath> #define LL __int64#define INF 0x3fffffffusing namespace Std;int g[105][105];int col[105];int k;bool bfs (int s) { Queue<int> p; P.push (s); Col[s] = 1; while (!p.empty ()) {int from = P.front (); P.pop (); for (int i = 1; I <= K; i++) {if (G[from][i] && col[i] = = 1) {P.push (i); Col[i] =!col[from];//dyed in different colors} if (G[from][i] && col[from] = = Col[i])//color has the same, it is not a binary chart return false; }} return true; int main () {//freopen ("d:\\a-small-2-attempt0.in", "R", stdin); Freopen ("D:\\output.txt", "w", stdout); int n,t,t=1; cin>>t; while (t--) {cin>>n; k=0; map<string,int>m; memset (g,0,sizeOf (G)); memset (col,-1, sizeof (COL)); for (int i=0;i<n;i++) {char a[105],b[105]; cin>>a>>b; if (!m[a]) m[a]=++k; if (!m[b]) m[b]=++k; G[m[a]][m[b]]=1; G[m[b]][m[a]]=1; } bool Flag=false; for (int i=1;i<=k;i++) {if (Col[i]==-1&&!bfs (i)) {flag=true; Break }} if (!flag) cout<< "Case #" <<t++<< ":" << "yes" <<endl; else cout<< "Case #" <<t++<< ":" << "No" <<endl; } return 0;} <strong></strong>
problem B. captain Hammer
Test instructions: The velocity and the horizontal displacement of the inclined parabolic motion are given, and the angle of oblique throw is obtained.
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include < algorithm> #include <queue> #include <set> #include <map> #include <vector> #include < Cmath> #define LL __int64#define INF 0x3fffffffusing namespace Std;int main () { //freopen ("D:\\test.txt", "R", stdin); Freopen ("D:\\output.txt", "w", stdout); int t,t=1; cin>>t; while (t--) { double v,d,c; cin>>v>>d; C=asin (9.8*d/v/v) * 180.0/3.1415926/2.0; cout<< "Case #" <<t++<< ":"; printf ("%.7f\n", c); } return 0;}
problem C. Moist
Test instructions: To n strings, ordered by the dictionary order, sorting method for the sweep from the top, encountered a smaller than the above, the swap position. Ask for the number of exchanges
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib > #include <algorithm> #include <queue> #include <set> #include <map> #include <vector> #include <cmath> #define LL __int64#define INF 0x3fffffffusing namespace Std;char s[105][105];int n;int main () { //freopen ("d:\\c-small-2-attempt0.in", "R", stdin); Freopen ("D:\\output.txt", "w", stdout); int t,t=1; cin>>t; while (t--) { cin>>n; GetChar (); for (int i=0;i<n;i++) { gets (s[i]); } int ans=0; for (int i=0;i<n;i++) {for (int j=0;j<i;j++) { if (strcmp (S[j],s[i]) >0) { swap (s[j],s[i]); ans++; Break ; }}} cout<< "Case #" <<t++<< ":" <<ans<<endl; } return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Google APAC University graduates test (Google School recruit written exam)