2013-8-14大一大二暑期组队训练赛

1001

Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 65535/65535K (Java/Other)
Total Submission(s) : 11   Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

You are to write a module that will check the correctness of given words using a known dictionary 
of all correct words  in all their forms, for a new spell checking program,. 
If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) 
that can be  obtained by one of the following operations: 
deleting of one letter from the word; 
replacing of one letter in the word with an arbitrary letter; 
inserting of one arbitrary letter into the word. Your task is to write the program that will find all
 possible replacements from the dictionary for  every given word. 

Input

The first part of the input file contains all words from the dictionary. Each word occupies its own line. 
This part is finished by the single character '#' on a separate line.
 All words are different. There will be at most 10000 words in the dictionary. 
The next part of the file contains all words that are to be checked. Each word occupies its own line. 
This part is also finished by the single character '#' on a separate line. There will be at most 50 
words that are to be checked. All words in the input file (words from the dictionary and words to be checked) 
consist only of small alphabetic characters and each one contains 15 characters at most. 

Output

Write to the output file exactly one line for every checked word in the order of their appearance 
in the second part of the  input file. If the word is correct (i.e. it exists in the dictionary) 
write the message: " is correct". If the word is not correct  then write this word first, 
then write the character ':' (colon), and after a single space write all its possible replacements, 
separated by spaces. The replacements should be written in the order of their appearance in the dictionary
 (in the first part of the input file). If there are no replacements for this word then the line feed 
should immediately  follow the colon(no space).

Sample Input

i
is
has
have
be
my
more
contest
me
too
if
award
#
me
aware
m
contest
hav
oo
or
i
fi
mre
#

Sample Output

me is correct
aware: award
m: i my me
contest is correct
hav: has have
oo: too
or: 
i is correct
fi: i
mre: more me


代码暂无

1002

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 23   Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子。要求摆放时任意的两个棋子不能放
在棋盘中的同一行或者同一列, 请编程求解对于给定形状和大小的棋盘,
摆放k个棋子的所有可行的摆放方案C。

Input

输入含有多组测试数据。 
每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,
以及摆放棋子的数目。 n <= 8 , k <= n 
当为-1 -1时表示输入结束。 
随后的n行描述了棋盘的形状:每行有n个字符,其中 # 表示棋盘区域, . 表示空白区域
(数据保证不出现多余的空白行或者空白列)。 

Output

对于每一组数据,给出一行输出,输出摆放的方案数目C (数据保证C<2^31)

Sample Input

2 1
#.
.#
4 4
...#
..#.
.#..
#...
-1 -1

Sample Output

2
1

//01479140	2013-08-14 16:22:53	Accepted	1002	62 MS	1600 KB	Java	hahacomeon

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
	private static char map[][];
	private static boolean vis[];
	static int n,sum=0,k;
	public static void main(String[] args) {
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		try {
			while(true){
				sum=0;
				String s[]=bf.readLine().split(" ");
				n=Integer.parseInt(s[0]);
				k=Integer.parseInt(s[1]);
				if(n==-1&&k==-1)
					break;
				map=new char[n][n];
				vis=new boolean[n];
				for(int i=0;i<n;i++){
					String str=bf.readLine();
					for(int j=0;j<str.length();j++)
						map[i][j]=str.charAt(j);
				}
				dfs(0,k);
				System.out.println(sum);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private static void dfs(int num,int k1) {
		if(k1==0){
			sum++;
			return;
		}
		if(num==n)
			return;
		for(int i=0;i<n;i++){
			if(map[num][i]=='#'&&!vis[i]){
				vis[i]=true;
				dfs(num+1,k1-1);
				vis[i]=false;
				
			}
		}
		dfs(num+1,k1);
	}
}

1003

Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 65535/65535K (Java/Other)
Total Submission(s) : 18   Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

A company uses trucks of different types. The company has its own code describing each type of a truck. 
The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special 
meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type
 was used but later other types were derived from it, then from the new types another types were derived,
 and so on. 

One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They 
defined the distance of truck types as the number of positions with different letters in truck type codes. 
They also assumed that each truck type was derived from exactly one other truck type (except for the first truck 
type which was not derived from any other type). The quality of a derivation plan was then defined as 
1/Σ(to,td)d(to,td)

where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type 
derived from it and d(to,td) is the distance of the types. 
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program 
should find the highest possible quality of a derivation plan. 

Input

The input consists of several test cases. Each test case begins with a line containing the number of truck types,
 N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code 
(a string of seven lowercase letters).
 You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same.
 The input is terminated with zero at the place of number of truck types.

Output

For each test case, your program should output the text "The highest possible quality is 1/Q.", 
where 1/Q is the quality of the best derivation plan.

Sample Input

4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0

Sample Output

The highest possible quality is 1/3.

#include <stdio.h>
#define M 2005
#define A 100000000
int n,sum;
int map[M][M],dis[M];
char s[M][8];
int min(int a,int b)
{
	return a<b?a:b;
}
void prim()
{
	int i,j,pos,p,min1;
	for(i=1;i<=n;i++)
		dis[i]=A;
	pos=1;
	sum=0;
	for(i=1;i<n;i++)
	{
		dis[pos]=-1;
		min1=A;
		for(j=1;j<=n;j++)
		{
			if(j!=pos&&dis[j]>=0)
			{
				dis[j]=min(dis[j],map[pos][j]);
				if(dis[j]<min1)
				{
					min1=dis[j];
					p=j;
				}
			}
		}
		pos=p;
		sum+=min1;
	}
}
int main()
{
	int i,j,k,t;
	while(scanf("%d",&n),n)
	{
		for(i=1;i<=n;i++)
		{
			scanf("%s",&s[i]);
			for(j=i-1;j>=1;j--)
			{
				for(k=0,t=0;k<7;k++)
					if(s[i][k]!=s[j][k])	
						t++;
					map[i][j]=map[j][i]=t;
			}
		}
		prim();
		printf("The highest possible quality is 1/%d.\n",sum);
	}
	return 0;
}

1004

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 65   Accepted Submission(s) : 20
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

John has N cows (1 ≤ N ≤ 80,000) 
Each cow i has a specified height hi (1 ≤ hi ≤ 1,000,000,000) and is standing in a line of cows all facing 
east (to the right in our diagrams). Therefore, cow i can see the tops of the heads of cows 
in front of her (namely cows i+1, i+2, and so on), for as long as these cows are strictly 
shorter than cow i.
Consider this example:
Num:  1 2 3 4 5 6
Height: 10 3 7 4 12 2
Cows facing right -->

Cow#1 can see the hairstyle of cows #2, 3, 4
Cow#2 can see no cow's hairstyle
Cow#3 can see the hairstyle of cow #4
Cow#4 can see no cow's hairstyle
Cow#5 can see the hairstyle of cow 6
Cow#6 can see no cows at all!
Let ci denote the number of cows whose hairstyle is visible from cow i; please compute the 
sum of c1 through cN. For this example, the desired is answer 3 + 0 + 1 + 0 + 1 + 0 = 5.

Input

Line 1: The number of cows, N. 
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow i.

Output

Line 1: A single integer that is the sum of c1 through cN.

Sample Input

6
10
3
7
4
12
2

Sample Output

5


import java.util.Scanner;
public class Main {//01479166	2013-08-14 16:32:23	Accepted	1004	265 MS	3688 KB	Java	hahacomeon
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(input.hasNext()){
			int n=input.nextInt();
			int a[]=new int[n];
			for(int i=0;i<n;i++){
				a[i]=input.nextInt();
			}
			int sum=0;
			for(int i=0;i<n-1;i++){
				for(int j=i+1;j<n&&a[j]<a[i];j++)
					sum++;
			}
			System.out.println(sum);
		}
	}
}

1005

Time Limit : 5000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 23   Accepted Submission(s) : 6
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

将字母A-Z编码,A为1,B为2,……依此类推,Z为26,则ABC编码为123。但是反向解码时,解码结果却不唯一,
比如123可以解码为 1-2-3:ABC,解码为12-3:LC,解码为1-23:AW
(注意,127不能解码为1-27,因为范围只能为1-26)。

Input

现给出一组编码后的数字串,让你求该数字串可以有几种解码方式(上例中,123对应着3种解码方式)。
问题输入将保证其为一个合法的数字串。比如100不是一个合法的数字串,
因为0或者00不代表一个字母;此外01不能视为1。

Output

解码方式总数。

Sample Input

25114
1111111111
3333333333

Sample Output

6
89
1

//01479251	2013-08-14 16:58:43	Accepted	1005	156 MS	2928 KB	Java	hahacomeon
import java.util.Scanner;
public class Main {
	private static int a[],sum=0,n;
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(input.hasNext()){
			sum=0;
			String s=input.nextLine();
			n=s.length();
			a=new int[n];
			//int a[]=new int[n];
			for(int i=0;i<s.length();i++){
				a[i]=(int)(s.charAt(i)-'0');
			}
			dfs(0);
			System.out.println(sum);
		}
	}
	private static void dfs(int i) {
		if(i==n){
			sum++;
			return;
		}
		if(a[i]==0)
			return;
		dfs(i+1);
		if(i+2<=n&&a[i]*10+a[i+1]<=26){
			dfs(i+2);
		}
	}
}

1006

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 45   Accepted Submission(s) : 23
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数
(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,
除非这个整数就是由若干个‘0’组成的,这时这个整数就是0)。

你的任务是:对这些分割得到的整数,依从小到大的顺序排序输出。

Input

输入包含多组测试用例,每组输入数据只有一行数字(数字之间没有空格),这行数字的长度不大于1000。 

输入数据保证:分割得到的非负整数不会大于100000000;输入数据不可能全由‘5’组成

Output

对于每个测试用例,输出分割得到的整数排序的结果,相邻的两个整数之间用一个空格分开,每组输出占一行。

Sample Input

0051231232050775

Sample Output

0 77 12312320

import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(input.hasNext()){
			String s=input.nextLine();
			String s1[]=s.split("5");
			int a[]=new int[s1.length];
			int e=0;
			for(int i=0;i<s1.length;i++){
				if(s1[i].length()>0){
					a[e++]=Integer.parseInt(s1[i]);
				}
			}
			Arrays.sort(a,0,e);
			for(int i=0;i<e-1;i++){
				System.out.print(a[i]+" ");
			}
			System.out.println(a[e-1]);
		}
	}
}

1007

Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 16   Accepted Submission(s) : 5
Font: Times New Roman | Verdana | Georgia
Font Size:  

Problem Description

编写程序,产生由2,3,5这3个数字符号所构成、长度为n的字符串,
并且在字符串中对于任何一个子串而言,都不会有相邻的、
完全相同的子串;

Input

字符串长度n(1<=n<=15);

Output

无相邻重复子串的所有字符串,每个字符串换行输出。

Sample Input

4

Sample Output

2325
2352
2353
2523
2532
2535
3235
3252
3253
3523
3525
3532
5232
5235
5253
5323
5325
5352

/*
 * 01479332	2013-08-14 17:43:41	Accepted	1007	187 MS	3908 KB	Java	hahacomeon
 */
import java.util.Scanner;
public class Main {
	private static int n;
	static String a[]={"2","3","5"};
	
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while(input.hasNext()){
			n=input.nextInt();
			String s="";
			dfs(n,s);
		}
	}
	private static void dfs(int n1, String s) {
		if(n-n1>1&&s.charAt(s.length()-1)==s.charAt(s.length()-2))
			return;
		if(n-n1>3)
			for(int i=s.length()-2;i>=s.length()/2;i--){
				boolean ok=false;
				for(int j=0;i-j>=s.length()/2;j++){
					String s2=s.substring(i-j);
					if((i-j)<s2.length()){
						ok=true;
						break;
					}
					String s3=s.substring((i-j)-s2.length(), i-j);
					if(s2.equals(s3))
						return;
				}
				if(ok)
					break;
			}
		if(n1==0)
		{
			System.out.println(s);
			return;
		}
		for(int i=0;i<3;i++){
			dfs(n1-1,s+a[i]);
		}
		
	}
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值