HHTC_学校集训编程题目(7)(个人赛_1)


学校开始个人赛了,划水又开始了
这些题有些是自己做的,有些是听别人讲解后写的~~
总之,就是菜!!!

A - Choose Your Words Carefully

Let’s face it, most students who do a good job on programming contest problems aren’t the best writers. However, there is no artistic process that a good programmer can’t improve with a little program to automate the process.
In this case, your writing problem is a tendency to use words too often. To help check for this,you are going to write a program that will search your papers for the word or words you use most often.

Input

The input consists entirely of your paper. Each line will be under 80 characters and will contain words, punctuation, and numbers. Words consist of the characters {a-z,A-Z,0-9}. Words are separated by whitespace, end-of-line, and punctuation. The punctuation that may be found includes the characters
,.;’`"()/:-
.No other characters will be found in the input.
The input ends at end-of-file.
Word comparisons are case-insensitive.

Output

Your output begins with the line:
< n > occurrences
where n is the number of times the most frequently appearing word occurs.
Following that line will be the words that occurred n times, one per line. The words must be listed in alphabetic order.

Sample Input

Fourscore and seven years ago our fathers brought forth on this
continent a new nation, conceived in liberty and dedicated to the
proposition that all men are created equal. Now we are engaged in
a great civil war, testing whether that nation or any nation so
conceived and so dedicated can long endure.

Sample Output

3 occurrences
and
nation

题目大意就是在一篇文章中找最多单词数~
使用map就好了,一个一个单词存放进去
AC代码:

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    char a[122];
    string s;
    int maxx = 1;
    map<string,int> mmp;
    while(scanf(" %s",a) != EOF){
        s.clear();
        int flag = 0;
        for(int i=0;i<strlen(a);i++){
            if(isalpha(a[i]) || (a[i] >= '0' && a[i] <= '9')){
                flag = 1;
                if(a[i] >= 'A' && a[i] <= 'Z'){
                    a[i] += 32;
                }
                s.push_back(a[i]);
            }else if(flag == 1){
                if(mmp.find(s) == mmp.end()){
                    mmp.insert(make_pair(s,1));
                }else{
                    mmp[s]++;
                    if(mmp[s] > maxx)
                        maxx = mmp[s];
                }
                s.clear();
                flag = 0;
            }
        }
        if(flag == 1){
            if(mmp.find(s) == mmp.end()){
                mmp.insert(make_pair(s,1));
            }else{
                mmp[s]++;
                if(mmp[s] > maxx)
                    maxx = mmp[s];
            }
        }
    }
    printf("%d occurrences\n",maxx);
    map<string ,int>::iterator it;
    for(it = mmp.begin();it != mmp.end();it++){
        if(it->second == maxx)
            printf("%s\n",it->first.c_str());
    }
    return 0;
}

B - Find the Clones

Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happen that there are 6 identical person named Hugh F. Bumblebee: the original person and its 5 copies. The Federal Bureau of Unauthorized Cloning (FBUC) charged you with the task of determining how many copies were made from each person. To help you in your task, FBUC have collected a DNA sample from each person. All copies of the same person have the same DNA sequence, and different people have different sequences (we know that there are no identical twins in the town, this is not an issue).

Input

The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 ≤ n ≤ 20000 people, and the length 1 ≤ m ≤ 20 of the DNA sequences. The next n lines contain the DNA sequences: each line contains a sequence of m characters, where each character is either ‘A’, ‘C’, ‘G’ or ‘T’.

The input is terminated by a block with n = m = 0 .

Output

For each test case, you have to output n lines, each line containing a single integer. The first line contains the number of different people that were not copied. The second line contains the number of people that were copied only once (i.e., there are two identical copies for each such person.) The third line contains the number of people that are present in three identical copies, and so on: the i -th line contains the number of persons that are present in i identical copies. For example, if there are 11 samples, one of them is from John Smith, and all the others are from copies of Joe Foobar, then you have to print ‘1’ in the first andthe tenth lines, and ‘0’ in all the other lines.

Sample Input

9 6
AAAAAA
ACACAC
GTTTTG
ACACAC
GTTTTG
ACACAC
ACACAC
TCCCCC
TCCCCC
0 0

Sample Output

1
2
0
1
0
0
0
0
0

Hint

Huge input file, ‘scanf’ recommended to avoid TLE.

题意就是找相同的有几个,然后按照顺序输出~
使用map
AC代码:

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

char str[20005][25];
int num[20005];

struct cmp{
    bool operator()(const char *a,const char *b)const
    {
        return strcmp(a,b)<0;
    }
};

map<char *,int, cmp> mmp;

int main()
{
    int n,m;
    char *s;
    while(scanf("%d %d",&n,&m) != EOF && (n != 0 || m != 0))
    {
        mmp.clear();
        int j = 0;
        for(int i = 0; i<n; i++)
        {
            s = str[j++];
            scanf("%s",s);
            mmp[s]++;
        }
        memset(num,0,sizeof(num));
        map<char *,int>::iterator it;
        for(it = mmp.begin(); it!=mmp.end(); it++)
        {
            num[it->second - 1]++;
        }
        for(int i = 0; i<n; i++)
        {
            printf("%d\n",num[i]);
        }
    }
    return 0;
}

F - Alaska

The Alaska Highway runs 1422 miles from Dawson Creek, British Columbia to Delta Junction, Alaska. Brenda would like to be the first person to drive her new electric car the length of the highway. Her car can travel up to 200 miles once charged at a special charging station. There is a charging station in Dawson Creek, where she begins her journey, and also several charging stations along the way. Can Brenda drive her car from Dawson City to Delta Juntion and back?

Input

The input contains several scenario. Each scenario begins with a line containing n, a positive number indicating the number of charging stations. n lines follow, each giving the location of a filling station on the highway, including the one in Dawson City. The location is an integer between 0 and 1422, inclusive, indicating the distance in miles from Dawson Creek. No two filling stations are at the same location. A line containing 0 follows the last scenario.

Output
For each scenario, output a line containing POSSIBLE if Brenda can make the trip. Otherwise, output a line containing the word IMPOSSIBLE.

Sample Input

2
0
900
8
1400
1200
1000
800
600
400
200
0
0

Sample Output

IMPOSSIBLE
POSSIBLE

简单题
AC代码:

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int arr[1500];

int main()
{
    int n,flag;
    while(scanf("%d",&n) != EOF && n)
    {
        flag=1;
        for(int i=0; i<n; i++)
            cin>>arr[i];
        sort(arr,arr+n,greater<int>());
        if(1422 - arr[0] > 100 || arr[n-1] > 100)//来回
            flag=0;
        if(flag){
            for(int i=0; i<n; i++)
            {
                if(arr[i]-arr[i+1] > 200)
                {
                    flag=0;
                    break;
                }
            }
        }
        if(flag)
            cout<<"POSSIBLE"<<endl;
        else
            cout<<"IMPOSSIBLE"<<endl;
    }
    return 0;
}

G - Substrings

You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.

Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string.

Output

There should be one line per test case containing the length of the largest string found.

Sample Input

2
3
ABCD
BCDFF
BRCD
2
rose
orchid

Sample Output

2
2

题意就是找最长字串~逆序也可以
直接暴力找
AC代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[105][105];
int n;
int solve()
{
	char sub[105];
	char rsub[105];
	int len=strlen(s[0]);
	int cnt;
	for(int l=len;l>0;l--)
	{
		for(int x=0;x+l<=len;x++)
		{
			memset(sub,0,sizeof(sub));
			memset(rsub,0,sizeof(rsub));
			strncpy(sub,s[0]+x,l);
			strcpy(rsub,sub);
			reverse(rsub,rsub+strlen(rsub));
			cnt=0;
			for(int i=1;i<n;i++)
			{
				if(strstr(s[i],sub)!=NULL||strstr(s[i],rsub)!=NULL)
				{
					cnt++;
				}
				else	break;
			}
			if(cnt==n-1)	return strlen(sub);
		}
	}
	return 0;
}
int main()
{
	int cas;
	scanf("%d",&cas);
	while(cas--)
	{
		scanf("%d",&n);
		memset(s,0,sizeof(s));
		for(int i=0;i<n;i++)
		{
			scanf("%s",s[i]);
		}
		printf("%d\n",solve());
	}
    return 0;
}

H - decimal system

As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12.
But after learning <>,we know that the computer will do the calculation as the following steps:
1 computer change the 3 into binary formality like 11;
2 computer change the 9 into binary formality like 1001;
3 computer plus the two number and get the result 1100;
4 computer change the result into decimal formality like 12;
5 computer export the result;

In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system.

Input

There will be several cases. The first line of each case contains one integers N, and N means there will be N numbers to import, then there will be N numbers at the next N lines, each line contains a number with such form : X1….Xn.(Y), and 0<=Xi<Y, 1<Y<=10. I promise you that the sum will not exceed the 100000000, and there will be at most 100 cases and the 0<N<=1000.

Output

There is only one line output case for each input case, which is the sum of all the number. The sum must be expressed using the decimal system.

Sample Input

3
1(2)
2(3)
3(4)

4
11(10)
11(2)
11(3)
11(4)

Sample Output

6
23

大概最简单的一道题目吧~
就是进制转化
AC代码:

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

long long jinzhi(int n,int m){
    long long sum = 0;
    long long p = 1;
    while(n){
        sum += (n % 10) * p;
        p *= m;
        n = n / 10;
    }
    return sum;
}

int main()
{
    int n,m;
    int T;
    while(scanf("%d",&T) != EOF){
        long long sum = 0;
        while(T--){
            scanf("%d(%d)",&n,&m);
            sum += jinzhi(n,m);
        }
        printf("%lld\n",sum);
    }
    return 0;
}

I - Secret

The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let’s index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers from the set Ui = (ui, 1, ui, 2, …, ui, |Ui|). Here and below we’ll presuppose that the set elements are written in the increasing order.

We’ll say that the secret is safe if the following conditions are hold:

for any two indexes i, j (1 ≤ i < j ≤ k) the intersection of sets Ui and Uj is an empty set;
the union of sets U1, U2, …, Uk is set (1, 2, …, n);
in each set Ui, its elements ui, 1, ui, 2, …, ui, |Ui| do not form an arithmetic progression (in particular, |Ui| ≥ 3 should hold).
Let us remind you that the elements of set (u1, u2, …, us) form an arithmetic progression if there is such number d, that for all i (1 ≤ i < s) fulfills ui + d = ui + 1. For example, the elements of sets (5), (1, 10) and (1, 5, 9) form arithmetic progressions and the elements of sets (1, 2, 4) and (3, 6, 8) don’t.

Your task is to find any partition of the set of words into subsets U1, U2, …, Uk so that the secret is safe. Otherwise indicate that there’s no such partition.

Input

The input consists of a single line which contains two integers n and k (2 ≤ k ≤ n ≤ 106) — the number of words in the secret and the number of the Keepers. The numbers are separated by a single space.

Output

If there is no way to keep the secret safe, print a single integer “-1” (without the quotes). Otherwise, print n integers, the i-th of them representing the number of the Keeper who’s got the i-th word of the secret.

If there are multiple solutions, print any of them.

Examples

Input
11 3
Output
3 1 2 1 1 2 3 2 2 3 1
Input
5 2
Output
-1

题意: n是1-n个数 k是集合的个数
每个集合中的个数必须大于等于3,
并且集合中的数从大到小排列后不能构成等差数列,
每个集合不能有交集,全部的并集为这个集合
利用一个比较简单得方法~~ 枚举
如下:n = 11 k =3
1 2 3 4 5 6 7 8 9 10 11
k为偶数时,下列式子符合条件:
1 2 3 4 4 3 2 1 1 2 3
1 2 3 4 5 6 7 8 9 10 11
k为奇数时,2这个集合不符合情况:
1 2 3 3 2 1 1 2 3 3 2
1 2 3 4 5 6 7 8 9 10 11
那么我们就交换一下位置
1 2 3 3 {1 2} 1 2 3 3 2
1 2 3 4 5 6 7 8 9 10 11
AC代码:

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int a[1000005];

void init(int n,int k)
{
    int j = 0;
    while(1)
    {
        for(int i=1; i<=k; i++)
        {
            a[j++] = i;
            n--;
            if(n==0){
                return ;
            }
        }
        for(int i = k ; i>=1; i--)
        {
            a[j++] = i;
            n--;
            if(n==0){
                return ;
            }
        }
    }
}
int main()
{
    int n,k;
    while(scanf("%d %d",&n,&k)!=EOF)
    {
        memset(a,0,sizeof(a));
        if(k*3>n){
            printf("-1\n");
            continue;
        }
        init(n,k);
        if(k%2!=0){
            int t = a[k/2+k];
            a[k/2+k] = a[k/2+k+1];
            a[k/2+k+1] = t;
        }
        for(int i=0;i<n;i++){
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值