Google2014年大中华区在线测试题

Problem 1

As the leader of the Evil League of Evil, Bad Horse has a lot of problems to deal with. Most recently, there have been far too many arguments and far too much backstabbing in the League, so much so that Bad Horse has decided to split the league into two departments in order to separate troublesome members. Being the Thoroughbred of Sin, Bad Horse isn't about to spend his valuable time figuring out how to split the League members by himself. That what he's got you -- his loyal henchman -- for.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case starts with a positive integer M on a line by itself -- the number of troublesome pairs of League members. The next M lines each contain a pair of names, separated by a single space.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is either "Yes" or "No", depending on whether the League members mentioned in the input can be split into two groups with neither of the groups containing a troublesome pair.

Limits

1 ≤ T ≤ 100.
Each member name will consist of only letters and the underscore character.
Names are case-sensitive.
No pair will appear more than once in the same test case.
Each pair will contain two distinct League members.

Small dataset

1 ≤ M ≤ 10.

Large dataset

1 ≤ M ≤ 100.

代码

bool g[1000][1000];


bool bfs(int s, int n, int *col){
	queue<int> p;  
	p.push(s);  
	col[s] = 1;
	while(!p.empty()){  
		int r = p.front();  
		p.pop();  
		for(int i = 0;i < n;i++){  
			if(g[r][i] && col[i] == -1){  
				p.push(i);  
				col[i] = 1-col[r];
			}  
			if(g[r][i] && col[r]==col[i])
				return false;  
		}  
	}  
	return true;
}

bool BipartiteGraph(int n){
	bool flag=false;
	int *color=new int[n];
	memset(color,-1,sizeof(int)*n);
	for(int i=0 ; i<n ; i++){
		if(color[i]==-1 && !dfs(i,n,color )){
			flag=true;
			break;
		}
	}
	delete color;
	return !flag;
}

void ConstructGraphFromFile(char path[], map<string,int>& strs){
	FILE *f,*o;
	if((f=fopen(path,"r"))==NULL)
		exit(-1);
    if((o=fopen("out.out","w+"))==NULL)
        exit(-1);
	int n,d,k;
	char str1[100],str2[100];
	fscanf(f,"%d",&n);
	for(int i=1 ; i<=n ; i++){
		k=0;
		fscanf(f,"%d",&d);
		while(d-->0){
			fscanf(f,"%s  %s",str1,str2);
			string s1(str1),s2(str2);
			if(strs.find(s1)==strs.end()){
				strs[s1]=k;
				k++;
			}
			if(strs.find(s2)==strs.end()){
				strs[s2]=k;
				k++;
			}
			g[strs[s1]][strs[s2]]=true;
			g[strs[s2]][strs[s1]]=true;
		}
		bool temp=BipartiteGraph(k);
		fprintf(o,"Case #%d: %s\n",i,temp?"Yes":"No");
		memset(g,false,sizeof(bool)*1000*1000);
		strs.clear();
	}
	fclose(f);
	fclose(o);
	return;
}

int main(int argc , char *argv[])
{
    map<string,int> strs;
    ConstructGraphFromFile("A-small-2-attempt0.in",strs);
    system("pause");
	return EXIT_SUCCESS;
}

Problem 2

The Hamjet is a true marvel of aircraft engineering. It is a jet airplane with a single engine so powerful that it burns all of its fuel instantly during takeoff. The Hamjet doesn't have any wings because who needs them when the fuselage is made of a special Wonderflonium isotope that makes it impervious to harm.

Piloting the Hamjet is a not a job for your typical, meek-bodied superhero. That's why the Hamjet belongs to Captain Hammer, who is himself impervious to harm. The G-forces that the pilot endures when taking a trip in the Hamjet are legen-dary.

The Hamjet takes off at an angle of θ degrees up and a speed of V meters per second. Vis a fixed value that is determined by the awesome power of the Hamjet engine and the capacity of its fuel tank. The destination is D meters away. Your job is to program the Hamjet's computer to calculate θ given V and D.

Fortunately, the Hamjet's Wondeflonium hull is impervious to air friction. Even more fortunately, the Hamjet doesn't fly too far or too high, so you can assume that the Earth is flat, and that the acceleration due to gravity is a constant 9.8  m/s 2  down.

Input

The first line of the input gives the number of test cases, TT lines follow. Each line will contain two positive integers -- V and D.

Output

For each test case, output one line containing "Case #x: θ", where x is the case number (starting from 1) and θ is in degrees up from the the horizontal. If there are several possible answers, output the smallest positive one.

An answer will be considered correct if it is within 10-6 of the exact answer, in absolute or relative error. See the FAQ for an explanation of what that means, and what formats of floating-point numbers we accept.

Limits

1 ≤ T ≤ 4500;
1 ≤ V ≤ 300;
1 ≤ D ≤ 10000;
It is guaranteed that each test case will be solvable.

void ConstructGraphFromFile(char path[]){
	FILE *f,*o;
	if((f=fopen(path,"r"))==NULL)
		exit(-1);
    if((o=fopen("F://out.out","w+"))==NULL)
        exit(-1);
	int n,V,D;
	char str1[100],str2[100];
	fscanf(f,"%d",&n);
	for(int i=1 ; i<=n ; i++){
	    fscanf(f,"%d %d",&V,&D);
	    fprintf(o,"Case #%d: %.7f\n",i,asin(9.8*((double)D)/((double)V)/((double)V))/3.1415926525*90);
	}
	fclose(f);
	fclose(o);
	return;
}

Problem 3

Moist has a hobby -- collecting figure skating trading cards. His card collection has been growing, and it is now too large to keep in one disorganized pile. Moist needs to sort the cards in alphabetical order, so that he can find the cards that he wants on short notice whenever it is necessary.

The problem is -- Moist can't actually pick up the cards because they keep sliding out his hands, and the sweat causes permanent damage. Some of the cards are rather expensive, mind you. To facilitate the sorting, Moist has convinced Dr. Horrible to build him a sorting robot. However, in his rather horrible style, Dr. Horrible has decided to make the sorting robot charge Moist a fee of $1 whenever it has to move a trading card during the sorting process.

Moist has figured out that the robot's sorting mechanism is very primitive. It scans the deck of cards from top to bottom. Whenever it finds a card that is lexicographically smaller than the previous card, it moves that card to its correct place in the stack above. This operation costs $1, and the robot resumes scanning down towards the bottom of the deck, moving cards one by one until the entire deck is sorted in lexicographical order from top to bottom.

As wet luck would have it, Moist is almost broke, but keeping his trading cards in order is the only remaining joy in his miserable life. He needs to know how much it would cost him to use the robot to sort his deck of cards.

Input

The first line of the input gives the number of test cases, TT test cases follow. Each one starts with a line containing a single integer, N. The next N lines each contain the name of a figure skater, in order from the top of the deck to the bottom.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of dollars it would cost Moist to use the robot to sort his deck of trading cards.

void ConstructGraphFromFile2(char path[]){
	FILE *f,*o;
	if((f=fopen(path,"r"))==NULL)
		exit(-1);
    if((o=fopen("F://out.out","w+"))==NULL)
        exit(-1);
	int n,k,count;
	char str[100];
	vector<string> strs;
	fscanf(f,"%d",&n);
	for(int i=1 ; i<=n ; i++){
	    fscanf(f,"%d\n",&k);
	    count=0;
	    for(int j=0,l ; j<k ; j++){
	        fgets(str,100,f);
	        string temp(str);
	        strs.push_back(temp);
	        for(l=j ; l-1>=0 ; l--){
	            if(temp<strs[l-1])
	               strs[l]=strs[l-1];
                else
                    break;
            }
            if(l!=j){
                count++;
                strs[l]=temp;
            }
        }  
        fprintf(o,"Case #%d: %d\n",i,count);  
        strs.clear();
	}
	fclose(f);
	fclose(o);
	return;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值