ACM:Aquarius's Trial

本文主要介绍了两个 ACM 竞赛问题。第一个问题是关于ACM ICPC世界编程锦标赛的团队组建,目标是组建最大数量的团队,每个团队成员需要至少参加过k次比赛,且每个人最多参加5次。第二个问题涉及将不同价值的大理石公平地分配给两个人,使得每个人获得的总价值相等。文章提供了输入输出示例和问题描述。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Choosing Teams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.

The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times?
Input

The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, …, yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship.
Output

Print a single number — the answer to the problem.
Examples
Input
Copy

5 2
0 4 5 1 0

Output
Copy

1

Input
Copy

6 4
0 1 2 3 4 5

Output
Copy

0

Input
Copy

6 5
0 0 0 0 0 0

Output
Copy

2

Note

In the first sample only one team could be made: the first, the fourth and the fifth participants.

In the second sample no teams could be created.

In the third sample two teams could be created. Any partition into two teams fits.

AC:

#include<stdio.h>

int main ()
{
	int n = 0, k = 0, every = 0, count = 0;

	scanf("%d%d", &n, &k);
	
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &every);
		if (every <= 5-k)
			count++;
	}
	printf("%d\n", count/3);
	return 0;
}

Dividing
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32471 Accepted Submission(s): 9162

Problem Description
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value.
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.

Input
Each line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, …, n6, where ni is the number of marbles of value i. So, the example from above would be described by the input-line ``1 0 1 2 0 0’’. The maximum total number of marbles will be 20000.

The last line of the input file will be ``0 0 0 0 0 0’’; do not process this line.

Output
For each colletcion, output Collection #k:'', where k is the number of the test case, and then eitherCan be divided.’’ or ``Can’t be divided.’’.

Output a blank line after each test case.

Sample Input

1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0

Sample Output

Collection #1:
Can’t be divided.

Collection #2:
Can be divided.

Source
Mid-Central European Regional Contest 1999

Recommend
JGShining

AC:

#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

int dp[500000] = {0};

int main()
{
	int a[11] = {0},sum = 0,val = 0,i = 0,j = 0,k = 0,ans = 0 ,cas = 1;
	while(~scanf("%d",&a[1]))
	{
		sum = a[1];
		for(i = 2;i<=6;i++)
		{
			scanf("%d",&a[i]);
			sum+=i*a[i];
		}
		if(!sum)
			break;
		printf("Collection #%d:\n",cas++);
		if(sum%2)
		{
			printf("Can't be divided.\n\n");
			continue;
		}
		val = sum/2;
		memset(dp,0,sizeof(dp));
		dp[0] = 1;
		for(i = 1;i<=6;i++)
		{
			if(!a[i])
				continue;
			for(j = 1;j<=a[i];j*=2)
			{
				ans = j*i;
				for(k = val;k>=ans;k--)
				{
					if(dp[k-ans])//必须前面的能够放入背包,现在的才能放入背包
						dp[k] = 1;
				}
				a[i]-=j;
			}
			ans = a[i]*i;
			if(ans)
			{
				for(k = val;k>=ans;k--)
				{
					if(dp[k-ans])
						dp[k] = 1;
				}
			}
		}
		if(dp[val])
			printf("Can be divided.\n\n");
		else
			printf("Can't be divided.\n\n");
	}

	return 0;
}

Human Gene Functions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4644 Accepted Submission(s): 2570

Problem Description
It is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have been interested in identifying human genes and determining their functions, because these can be used to diagnose human diseases and to design new drugs for them.

A human gene can be identified through a series of time-consuming biological experiments, often with the help of computer programs. Once a sequence of a gene is obtained, the next job is to determine its function. One of the methods for biologists to use in determining the function of a new gene sequence that they have just identified is to search a database with the new gene as a query. The database to be searched stores many gene sequences and their functions – many researchers have been submitting their genes and functions to the database and the database is freely accessible through the Internet.

A database search will return a list of gene sequences from the database that are similar to the query gene. Biologists assume that sequence similarity often implies functional similarity. So, the function of the new gene might be one of the functions that the genes from the list have. To exactly determine which one is the right one another series of biological experiments will be needed.

Your job is to make a program that compares two genes and determines their similarity as explained below. Your program may be used as a part of the database search if you can provide an efficient one.

Given two genes AGTGATG and GTTAG, how similar are they? One of the methods to measure the similarity of two genes is called alignment. In an alignment, spaces are inserted, if necessary, in appropriate positions of the genes to make them equally long and score the resulting genes according to a scoring matrix.

For example, one space is inserted into AGTGATG to result in AGTGAT-G, and three spaces are inserted into GTTAG to result in –GT–TAG. A space is denoted by a minus sign (-). The two genes are now of equal length. These two strings are aligned:

AGTGAT-G
-GT–TAG

In this alignment, there are four matches, namely, G in the second position, T in the third, T in the sixth, and G in the eighth. Each pair of aligned characters is assigned a score according to the following scoring matrix.

  • denotes that a space-space match is not allowed. The score of the alignment above is (-3)+5+5+(-2)+(-3)+5+(-3)+5=9.

Of course, many other alignments are possible. One is shown below (a different number of spaces are inserted into different positions):

AGTGATG
-GTTA-G

This alignment gives a score of (-3)+5+5+(-2)+5+(-1) +5=14. So, this one is better than the previous one. As a matter of fact, this one is optimal since no other alignment can have a higher score. So, it is said that the similarity of the two genes is 14.

Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case consists of two lines: each line contains an integer, the length of a gene, followed by a gene sequence. The length of each gene sequence is at least one and does not exceed 100.

Output
The output should print the similarity of each test case, one per line.

Sample Input

2
7 AGTGATG
5 GTTAG
7 AGCTATT
9 AGCTTTAAA

Sample Output

14
21

Source
Asia 2001, Taejon (South Korea)

Recommend

AC:

#include <stdio.h>
#include <string.h>
int value[5][5]= {5, -1, -2, -1, -3,
				  -1, 5, -3, -2, -4,
				  -2, -3, 5, -2, -2,
				  -1, -2, -2, 5, -1,
				  -3, -4, -2, -1};
int res(char x)
{
	switch(x)
	{
	case 'A': return 0;
	case 'C': return 1;
	case 'G': return 2;
	case 'T': return 3;
	case '-': return 4;
	}

}

int max(int a, int b ,int c)
{
	int m;
	if(a > b)
		m = a;
	else m = b;
	if(c> m)
		m = c;
	return m;
}

void solve(int n, int m, char *s1, char *s2)
{
	int i = 0, j = 0,d1 = 0,d2 = 0,d3 = 0;
	int dp[200][200] = {0};

	for(i=1; i<=n; i++)
		 dp[i][0] = dp[i-1][0] + value[res(s1[i])][res('-')];
	for(j=1; j<=m; j++)
		dp[0][j] = dp[0][j-1] + value[res('-')][res( s2[j])];

	for(i=1; i<=n; i++)
	{
		for(j=1; j<=m; j++)
		{
			d1 = value[res(s1[i])][res(s2[j])] + dp[i-1][j-1];
			d2 =dp[i][j-1] + value[res('-')][res( s2[j])];
			d3 =dp[i-1][j] + value[res(s1[i])][res('-')];
			dp[i][j] = max(d1,d2, d3);
		}
	}
	printf("%d\n", dp[n][m]);
}

int main()
{
	int i, total = 0, n = 0, m;
	char gene1[200], gene2[200];

	scanf("%d",&total);
	while(total--)
	{
		scanf("%d", &n);getchar();	
		for(i=1; i<=n; i++)
			scanf("%c", &gene1[i]);

		scanf("%d", &m);getchar();
		for(i=1; i<=m; i++)
			scanf("%c", &gene2[i]);

		solve(n, m, gene1, gene2);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值