多校联赛第二场

Keep On Movin

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 568    Accepted Submission(s): 385


Problem Description
Professor Zhang has kinds of characters and the quantity of the  i-th character is  ai. Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximize the length of the shortest palindromic string.

For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is  {2,3,2,2} . Professor Zhang can build {"acdbbbdca"}, {"abbba", "cddc"}, {"aca", "bbb", "dcd"}, or {"acdbdca", "bb"}. The first is the optimal solution where the length of the shortest palindromic string is 9.

Note that a string is called palindromic if it can be read the same way in either direction.
 

Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer  n  (1n105) -- the number of kinds of characters. The second line contains  n integers  a1,a2,...,an  (0ai104).
 

Output
For each test case, output an integer denoting the answer.
 

Sample Input
 
   
4 4 1 1 2 4 3 2 2 2 5 1 1 1 1 1 5 1 1 2 2 3
 

Sample Output
 
   
3 6 1 3

#include
#include
#include
#define INF 9999999;
using namespace std;

int main()
{
	int T,n,i,j,k,t,i1;
	int count=0;
	long long sum=0;
	long long re;
	scanf("%d",&T);
	for(i1=0;i1




It's All In The Mind

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Professor Zhang has a number sequence  a_1,a_2,...,a_n. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence:

1. For every  i \in \{1,2,...,n\}0 \le a_i \le 100.
2. The sequence is non-increasing, i.e.  a_1 \ge a_2 \ge ... \ge a_n.
3. The sum of all elements in the sequence is not zero.

Professor Zhang wants to know the maximum value of  \frac{a_1+a_2}{\sum_{i=1}^{n}{a_i}}  among all the possible sequences.
 

Input
There are multiple test cases. The first line of input contains an integer  T , indicating the number of test cases. For each test case:

The first contains two integers  n  and  m   (2 \le n \le 100, 0 \le m \le n)  -- the length of the sequence and the number of known elements.

In the next  m  lines, each contains two integers  x_i  and  y_i   (1 \le x_i \le n, 0 \le y_i \le 100, x_i < x_{i+1}, y_i \ge y_{i+1}) , indicating that  a_{x_i} = y_i .
 

Output
For each test case, output the answer as an irreducible fraction " p / q ", where  p q  are integers,  q > 0 .
 

Sample Input
 
   
2 2 0 3 1 3 1
 

Sample Output
 
   
1/1 200/201



#include
#include
#include
#define INF 9999999;
using namespace std;
int num[105];
int flag[105];
int main()
{
	int T,n,i,j,k,t,i1,m,x,y,flag1,flag2,sum,sum1;
	scanf("%d",&T);
	for(i1=0;i1=3;i--)
		{
			if(flag[i]==0)  num[i]=num[i+1];
		}
		for(i=1;i<=n;i++)
			sum+=num[i]; 
		sum1=num[1]+num[2];
		for(j=1;j<50;j++)
		{
			for(i=2;i<=100;i++)
			{
				if(sum%i==0&&sum1%i==0)
				{
					sum/=i;
					sum1/=i;
				}
			}
		
		}
		
		printf("%d/%d\n",sum1,sum);
	}
	return 0;
} 





你可能感兴趣的:(ACM_比赛题目)