HDU校赛

The Country List

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


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

题意:

给n个城市名,若两个城市名长度相等且有超过2个字符相同(>2个,wa这了。。),则它们是不能被识别的。问有多少个城市名是不能识别的。

解题思路: 模拟

AC代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

void fun(char s[])
{
    int l=strlen(s);
    for(int i=0;i<l;i++){
        if(s[i]>='A'&&s[i]<='Z'){
            s[i]=s[i]-'A'+'a';
        }
    }
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){
        char s[110][30];
        for(int i=0;i<n;i++){
            scanf("%s",s[i]);
            fun(s[i]);
        }
        int res=0;
        bool vis[110];
        memset(vis,false,sizeof(vis)); 
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(!vis[j]||!vis[i]){
                    if(strlen(s[i])==strlen(s[j])){
                        int num=0;
                        for(int k=0;k<strlen(s[i]);k++){
                            if(s[i][k]==s[j][k]) num++;
                            if(num>2){
                                if(!vis[i]){
                                    vis[i]=true;
                                    res++;
                                }
                                if(!vis[j]){
                                    vis[j]=true;res++;break;
                                }
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n",res);
    }
    return 0;
}

The Magic Tower

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


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
 


题意:

给定W和B的血量、攻击力和防御力,并给出谁先攻击,问谁可以胜。若W不能杀死B,算W输。

解题思路:

分类讨论,不能纯暴力模拟,会超时。

AC代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main()
{
	char s[3];
	while(scanf("%s",s)==1){
		int n[2][3];
		for(int i=0;i<2;i++){
			for(int j=0;j<3;j++)
				scanf("%d",&n[i][j]);
		}
		int k;
		if(strcmp(s,"W")==0) k=0;
		else k=1;
		int d1=n[0][1]-n[1][2];
		if(d1<=0){
			puts("Warrior loses");
			continue;
		}
		int d2=n[1][1]-n[0][2];
		if(d2<=0){
			puts("Warrior wins");
			continue;
		} 
		int s2=n[1][0]/d1;
		if(n[1][0]%d1) s2++;
		int s1=n[0][0]/d2;
		if(n[0][0]%d2) s1++;
		if(s1>s2)puts("Warrior wins");
		else if(s1==s2){
			if(k==0)puts("Warrior wins");
			else puts("Warrior loses");
		}
		else puts("Warrior loses");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值