多校联赛第二场

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<stdio.h>
#include<string.h>
#include<algorithm>
#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<T;i1++)
	{
		re=0; 
		count=0; 
		sum=0; 
		scanf("%d",&n);
		j=0;
		for(k=0;k<n;k++)
		{
			scanf("%d",&t);
			if(t%2==1)
			{
				sum    =sum+ t-1;
				count++;
			}
			else{
				sum+=t; 
			}
		}
		
		if(count == 0)
		{
			printf("%lld\n",sum);
		} 
		else
		{
			re=((sum/2)/count)*2+1;
			printf("%lld\n",re);
		}
	}
	return 0;
} 










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<stdio.h>
#include<string.h>
#include<algorithm>
#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<T;i1++)
	{
		sum1=0;
		sum=0;
		flag1=0;
		flag2=0;
		memset(num,0,sizeof(num));
		memset(flag,0,sizeof(flag));
		scanf("%d %d",&n,&m);
		for(i=0;i<m;i++)
		{
			scanf("%d %d",&x,&y);
			flag[x]++;
			num[x]=y;
		} 
		
		if(flag[1] == 1&&flag[2] == 0)
		{
			num[2]=num[1];
			flag[2]++;
		} else if(flag[1] == 0&&flag[2]==1)
		{
			num[1]=100;
			 flag[1]++;
		} else if(flag[1] == 0 && flag[2] == 0)
		{
			num[1]=100;
			num[2]=100;
			flag[1]++;
			flag[2]++;
		}
		
		
		if(flag[n]==0)   num[n]=0;
		
		for(i=n-1;i>=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;
} 





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值