2013-8-14大一大二暑期组队训练赛
生活随笔
收集整理的這篇文章主要介紹了
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 -1Sample Output
2 1//01479140 2013-08-14 16:22:53 Accepted 1002 62 MS 1600 KB Java hahacomeonimport 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 0Sample 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 2Sample Output
5import java.util.Scanner; public class Main {//01479166 2013-08-14 16:32:23 Accepted 1004 265 MS 3688 KB Java hahacomeonpublic 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 3333333333Sample 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
0051231232050775Sample Output
0 77 12312320import 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
4Sample 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]);}} }
?
總結
以上是生活随笔為你收集整理的2013-8-14大一大二暑期组队训练赛的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信捷PLC应用-三轴钻孔机
- 下一篇: 45个极具冲击力的WordPress摄影