杭电校赛(虐哭。。。)

写了半天写三道水题。。。虐哭。。。。

The Country List

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable to be a volunteer of such an international pageant. His job is to guide the foreign visitors. Although he has a strong desire to be an excellent volunteer, the lack of English makes him annoyed for a long time.  Some countries’ names look so similar that he can’t distinguish them. Such as: Albania and Algeria. If two countries’ names have the same length and there are more than 2 same letters in the same position of each word, CC cannot distinguish them. For example: Albania and AlgerIa have the same length 7, and their first, second, sixth and seventh letters are same. So CC can’t distinguish them. Now he has received a name list of countries, please tell him how many words he cannot distinguish. Note that comparisons between letters are case-insensitive.
 
Input
There are multiple test cases. Each case begins with an integer n (0 < n < 100) indicating the number of countries in the list. The next n lines each contain a country’s name consisted by ‘a’ ~ ‘z’ or ‘A’ ~ ‘Z’. Length of each word will not exceed 20. You can assume that no name will show up twice in the list.
 
Output
For each case, output the number of hard names in CC’s list.
 
Sample Input
3 Denmark GERMANY China 4 Aaaa aBaa cBaa cBad
 
Sample Output
2 4
 

水题。让判断不可区分字符串的个数;

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
#include<queue>
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PL(x) printf("%lld",x)
typedef long long LL;
using namespace std;
struct Node{
	char s[25];
	int len;
};
bool js(Node a,Node b){
	int temp=0;
	for(int i=0;i<a.len;i++){
		if(a.s[i]==b.s[i]||abs(a.s[i]-b.s[i])=='a'-'A')temp++;
		if(temp>2)return true;
	}
	return false;
}
Node dt[110];
int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++)scanf("%s",dt[i].s),dt[i].len=strlen(dt[i].s);
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==j||dt[i].len!=dt[j].len)continue;
				if(js(dt[i],dt[j])){
					ans++;
					break;
				}
			}
		}
		printf("%d
",ans);
	}
	return 0;
}

  

Happy Value

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
In an apartment, there are N residents. The Internet Service Provider (ISP) wants to connect these residents with N – 1 cables.  However, the friendships of the residents are different. There is a “Happy Value” indicating the degrees of a pair of residents. The higher “Happy Value” is, the friendlier a pair of residents is. So the ISP wants to choose a connecting plan to make the highest sum of “Happy Values”.
 
Input
There are multiple test cases. Please process to end of file. For each case, the first line contains only one integer N (2<=N<=100), indicating the number of the residents. Then N lines follow. Each line contains N integers. Each integer Hij(0<=Hij<=10000) in ith row and jth column indicates that ith resident have a “Happy Value” Hij with jth resident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
 
Output
For each case, please output the answer in one line.
 
Sample Input
2 0 1 1 0 3 0 1 5 1 0 3 5 3 0
 
Sample Output
1 8

 题解:最小生成树模版题,哦,是最大;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PL(x) printf("%lld",x)
typedef long long LL;
const int MAXN=110;
int mp[MAXN][MAXN];
int ans;
int N;
int low[MAXN];
int vis[MAXN];
void prim(){
	mem(low,INF);mem(vis,0);
	for(int i=1;i<=N;i++)low[i]=mp[1][i];
	vis[1]=1;
	while(true){
		int temp=-INF,k;
		for(int i=1;i<=N;i++)
			if(!vis[i]&&low[i]>temp)temp=low[k=i];
		if(temp==-INF)break;
		vis[k]=1;
		ans+=temp;
		for(int i=1;i<=N;i++)
			if(!vis[i])low[i]=max(low[i],mp[k][i]);
	}
}
int main(){
	while(~scanf("%d",&N)){
		for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++){
			SI(mp[i][j]);
		}
		ans=0;
		prim();
		printf("%d
",ans);
	}
	return 0;
}

  

The Magic Tower

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
Like most of the RPG (role play game), “The Magic Tower” is a game about how a warrior saves the princess.  After killing lots of monsters, the warrior has climbed up the top of the magic tower. There is a boss in front of him. The warrior must kill the boss to save the princess. Now, the warrior wants you to tell him if he can save the princess.
 
Input
There are several test cases. For each case, the first line is a character, “W” or “B”, indicating that who begins to attack first, ”W” for warrior and ”B” for boss. They attack each other in turn.  The second line contains three integers, W_HP, W_ATK and W_DEF. (1<=W_HP<=10000, 0<=W_ATK, W_DEF<=65535), indicating warrior’s life point, attack value and defense value.  The third line contains three integers, B_HP, B_ATK and B_DEF. (1<=B_HP<=10000, 0<=B_ATK, B_DEF<=65535), indicating boss’s life point, attack value and defense value. 
Note: warrior can make a damage of (W_ATK-B_DEF) to boss if (W_ATK-B_DEF) bigger than zero, otherwise no damage. Also, boss can make a damage of (B_ATK-W_DEF) to warrior if (B_ATK-W_DEF) bigger than zero, otherwise no damage. 
 
Output
For each case, if boss’s HP first turns to be smaller or equal than zero, please print ”Warrior wins”. Otherwise, please print “Warrior loses”. If warrior cannot kill the boss forever, please also print ”Warrior loses”.
 
Sample Input
W 100 1000 900 100 1000 900 B 100 1000 900 100 1000 900
 
Sample Output
Warrior wins Warrior loses

水题;找用多少时间就可以了,注意特判等于0的情况;

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define PI(x) printf("%d",x)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PL(x) printf("%lld",x)
typedef long long LL;
const double DOT=0.999999999999999;
int main(){
	char s[2];
	int W_h,W_a,W_d,B_h,B_a,B_d;
	while(~scanf("%s",s)){
		scanf("%d%d%d%d%d%d",&W_h,&W_a,&W_d,&B_h,&B_a,&B_d);
		int t1,t2;
		if(W_a<=B_d){
			puts("Warrior loses");
			continue;
		}
		if(B_a<=W_d){
			puts("Warrior wins");
			continue;
		}
		t1=(int)DOT+B_h/(W_a-B_d);
		t2=(int)DOT+W_h/(B_a-W_d);
		int flot=0;
		if(s[0]=='W')flot=1;
		if(t1>t2)puts("Warrior loses");
		else if(t1==t2&&!flot)puts("Warrior loses");
		else puts("Warrior wins");
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/handsomecui/p/5078329.html