2019CCPC-江西省赛(重现赛)- 感谢南昌大学

这次江西省赛的重现赛,一共解了4题,整体感觉不怎么好,能做更好的。
。。。。不废话了,看解题吧。

K题是本次比赛的水体,

K - Class HDU - 6577

Avin has two integers a, b (1 ≤ a, b ≤ 1, 000).
Given x = a + b and y = a - b, can you calculate ab?
Input
The first line contains two integers x, y.
Output
Print the result of a
b.
Sample Input
4 2
Sample Output
3

代码:

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <cmath>
#include <functional>
#define INF (1<<30)
#define il inline
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define down(i,x,y) for(int i=(x);i>=(y);i--)
using namespace std;
int const N=1e5+10;
typedef long long ll;
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	int a=(x+y)/2;
	int b=x-a;
	printf("%d\n",a*b);
	return 0;
}

F - String HDU - 6572
Avin has a string. He would like to uniform-randomly select four characters (selecting the same character is allowed) from it. You are asked to calculate the probability of the four characters being ”avin” in order.
Input
The first line contains n (1 ≤ n ≤ 100), the length of the string. The second line contains the string. To simplify the problem, the characters of the string are from ’a’, ’v’, ’i’, ’n’.
Output
Print the reduced fraction (the greatest common divisor of the numerator and denominator is 1), representing the probability. If the answer is 0, you should output “0/1”.
Sample Input
4
avin
4
aaaa
Sample Output
1/256
0/1

题意:求avin的概率,统计avin每个字符的个数,乘积作为分母,分子是个数的4次方,然后求gcd约分即可。

代码:

#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <cmath>
#include <functional>
#define INF (1<<30)
#define il inline
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define down(i,x,y) for(int i=(x);i>=(y);i--)
using namespace std;
char s[110];
int num[10];
int n;
il int gcd(int a,int b)
{
	while(b^=a^=b^=a%=b);
	return a;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++)
	{
		num[s[i]-'a']++;
	}
	int fenzi=num[0]*num['v'-'a']*num['i'-'a']*num['n'-'a'];
	if(fenzi==0)
	{
		printf("0/1\n");
		return 0;
	}
	int fenmu=pow(n,4);
	int k=gcd(fenmu,fenzi);
	printf("%d/%d\n",fenzi/k,fenmu/k);
	return 0;
}

I - Budget HDU - 6575

Avin’s company has many ongoing projects with different budgets. His company records the budgets using numbers rounded to 3 digits after the decimal place. However, the company is updating the system and all budgets will be rounded to 2 digits after the decimal place. For example, 1.004 will be rounded down
to 1.00 while 1.995 will be rounded up to 2.00. Avin wants to know the difference of the total budget caused by the update.
Input
The first line contains an integer n (1 ≤ n ≤ 1, 000). The second line contains n decimals, and the i-th decimal ai (0 ≤ ai ≤ 1e18) represents the budget of the i -th project. All decimals are rounded to 3 digits.
Output
Print the difference rounded to 3 digits…
Sample Input
1
1.001
1
0.999
2
1.001 0.999
Sample Output
-0.001
0.001
0.000

题意:每个小数,四舍五入保留2为小数,保留后和保留前的差值是多少,题目很简单,精度问题一直wa,最后队友用char字符串过的,赛后,查了java 自带API,秒A。

代码:

import java.math.BigDecimal;
import java.util.Scanner; public class Main 
{ 
	public static void main(String[] args)
	{
		// TODO Auto-generated method stub 
		Scanner sc=new Scanner(System.in); 
		while(sc.hasNext())
		{
			int n=sc.nextInt();
			BigDecimal sum1=BigDecimal.ZERO;
			BigDecimal sum2=BigDecimal.ZERO;
			for(int i=0;i<n;i++)
			{
				BigDecimal zhi=sc.nextBigDecimal();
				sum1=sum1.add(zhi);
				sum2=sum2.add(zhi.setScale(2, BigDecimal.ROUND_HALF_UP));
			}
			System.out.printf("%.3f\r\n", sum2.subtract(sum1).doubleValue());
		}
		
	}
}

G - Traffic HDU - 6573

Avin is observing the cars at a crossroads. He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time ai . There are another m cars running in the north-south direction with the i-th car passing the intersection at time bi . If two cars passing the intersections at the same time, a traffic crash occurs. In order to achieve world peace and harmony, all the cars running in the north-south direction wait the same amount of integral time so that no two cars bump. You are asked the minimum waiting time.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 1, 000). The second line contains n distinct integers ai (1 ≤ ai ≤ 1, 000). The third line contains m distinct integers bi (1 ≤ bi ≤ 1, 000).
Output
Print a non-negative integer denoting the minimum waiting time.
Sample Input
1 1
1
1
1 2
2
1 3
Sample Output
1
0

题意:给定东西方向的小车,和南北方向的小车,2者行驶的时间必须错开, 队友AC的,暴力判断南北方向的时间点和东西方向的时间点是不是有重叠,重叠都++再判断

代码:


import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner f=new Scanner(System.in);
		while(f.hasNext())
		{
			int a=f.nextInt();
			int b=f.nextInt();
			int jg=0;
			int max=b;
			if(a>b)
				max=a;
			int s[]=new int[2000];
			int w[]=new int[2000];
			for(int i=1;i<=a;i++)
			{
				s[i]=f.nextInt();
			}
			for(int i=1;i<=b;i++)
			{
				w[i]=f.nextInt();
			}
			while(1==1)
			{
				if(cx(s,w,max)==0)
				{
					break;
				}
				for(int i=1;i<=b;i++)
				{
					w[i]++;
				}
				jg++;
			}
			System.out.println(jg);
		}
	}
	public static int cx(int s[],int w[],int max)
	{
		for(int i=1;i<=max;i++)
		{
			for(int j=1;j<=max;j++)
			{
				if(s[i]==w[j])
				{
					
					return 1;
				}
			}
		}
		return 0;
	}

}

J - Worker HDU - 6576
Avin meets a rich customer today. He will earn 1 million dollars if he can solve a hard problem. There are n warehouses and m workers. Any worker in the i-th warehouse can handle ai orders per day. The customer wonders whether there exists one worker assignment method satisfying that every warehouse handles the same number of orders every day. Note that each worker should be assigned to exactly one warehouse and no worker is lazy when working.
Input
The first line contains two integers n (1 ≤ n ≤ 1, 000), m (1 ≤ m ≤ 1018). The second line contains n integers. The i-th integer ai (1 ≤ ai ≤ 10) represents one worker in the i-th warehouse can handle ai orders per day.
Output
If there is a feasible assignment method, print “Yes” in the first line. Then, in the second line, print n integers with the i-th integer representing the number of workers assigned to the i-th warehouse.
Otherwise, print “No” in one line. If there are multiple solutions, any solution is accepted.
Sample Input
2 6
1 2
2 5
1 2
Sample Output
Yes
4 2
No

题意:分配工人,让工作量都一样,要分配完。求个lcm即可
然后在放大。

代码:

#include <cstdio> 
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <functional>
#define INF (1<<30)
#define il inline
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define down(i,x,y) for(int i=(x);i>=(y);i--)
using namespace std;
int const maxn=1005;
typedef long long ll;
ll n,m;
ll a[maxn],b[maxn];
il ll gcd(ll a,ll b)
{
	while(b^=a^=b^=a%=b);
	return a;
}
il ll lcm(ll a,ll b)
{
	return a*b/gcd(a,b);
}
int main()
{
	while(~scanf("%lld%lld",&n,&m))
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i=0;i<n;i++)
		{
			scanf("%lld",&a[i]);
		}
		ll lc=a[0];
		ll sum=0;
		for(int i=1;i<n;i++)
		{
			lc=lcm(lc,a[i]);
		}
		for(int i=0;i<n;i++)
		{
			b[i]=lc/a[i];
			sum+=b[i];
		}
		if(m%sum!=0)
		{
			printf("No\n");
		}
		else
		{
			printf("Yes\n");
			for(int i=0;i<n;i++)
			{
				printf("%lld%c",b[i]*m/sum,i==n-1?'\n':' ');
			}
		}
	}
	return 0;
}

D - Wave HDU - 6570
Avin is studying series. A series is called “wave” if the following conditions are satisfied:

  1. It contains at least two elements;
  2. All elements at odd positions are the same;
  3. All elements at even positions are the same;
  4. Elements at odd positions are NOT the same as the elements at even positions.
    You are given a series with length n. Avin asks you to find the longest “wave” subseries. A subseries is a subsequence of a series.
    Input
    The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a “wave” subseries.
    Output
    Print the length of the longest “wave” subseries.
    Sample Input
    5 3
    1 2 1 3 2
    Sample Output
    4

题意:给出一个序列,基数位置和偶数位置都要一样,并且不相等,这些数在c的范围,由于c最大只有100,所以我们暴力枚举c,这题我们只需要知道对应数字的位置即可,用一个vector数组存每个数的位置,然后2个下标去跑就好了。

代码:

#include <cstdio> 
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <functional>
#define INF (1<<30)
#define il inline
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define down(i,x,y) for(int i=(x);i>=(y);i--)
using namespace std;
int const maxn=100000+100;
int a[maxn];
vector<int>v[maxn];
int n,c;
int main()
{
	scanf("%d%d",&n,&c);
	rep(i,1,n)
	{
		scanf("%d",&a[i]);
		v[a[i]].push_back(i);
	}
	int maxx=-INF;
	rep(i,1,c)
	{
		rep(j,1,c)
		{
			if(i==j)continue;
			int flag=1;
			int l=0;
			int r=0;
			int len=0;
			int s=0;
			int f=0;
			while(l<v[i].size()&&r<v[j].size())
			{
				if(flag)
				{
					while(l<v[i].size()&&v[i][l]<f)l++;
					s=v[i][l];
					if(l<v[i].size())len++;
					flag=0;
				}
				else
				{
					while(r<v[j].size()&&v[j][r]<s)r++;
					f=v[j][r];
					if(r<v[j].size())len++;
					flag=1;
				}
			}
			maxx=max(maxx,len);
		}
	}
	printf("%d\n",maxx);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值