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

趁着多校之际打了一下这个比赛,low的一批。做了七个题,被虐的不轻
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
    首先,n很大,1e5。但是我们发现这个c很小。我们可以把每个数的位置记录下来,枚举每两个数他们出现的位置,复杂度不是很大。
    代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

const int maxx=1e2+100;
vector<int> p[maxx];
int n,m;

int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		int x;
		for(int i=1;i<=m;i++) p[i].clear();
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			p[x].push_back(i);
		}
		int ans=0,maxn=0;
		int len1,len2,y;
		for(int i=1;i<=m;i++)
		{
			for(int j=i+1;j<=m;j++)
			{
				ans=0;
				len1=p[i].size();
				len2=p[j].size();
				x=y=0;
				int flag=0;
				if(p[i][0]<p[j][0]) flag=1;
				if(flag) x++;else y++;ans++;
				while(x<len1&&y<len2)
				{
					if(flag==0)
					{
						while(p[i][x]<p[j][y-1]&&x<len1) x++;
						if(x<len1)
						{
							x++;
							ans++;
							flag=1;
						}
						else break;
						if(x==len1)
						{
							while(y<len2)
							{
								if(p[j][y]>p[i][x-1])
								{
									ans++;
									break;	
								}
								y++;
							}
							break;
						}
					}
					else
					{
						//cout<<p[j][y]<<endl;
						while(p[j][y]<p[i][x-1]&&y<len2) y++;
						if(y<len2)
						{
							y++;
							ans++;
							flag=0;
						}
						else break;
						if(y==len2)
						{
							while(x<len1)
							{
								if(p[i][x]>p[j][y-1])
								{
									ans++;
									break;
								}
								x++;
							}
							break;
						}
 					}
				}
				maxn=max(maxn,ans);
			}
		}
		printf("%d\n",maxn);
	}
}

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
很简单的概率问题,数学纯暴力
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;

string s;
int n;

int gcd(int x,int y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}
int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		cin>>s;
		int cnt1=0;
		int cnt2=0;
		int cnt3=0;
		int cnt4=0;
		int len=s.length();
		for(int i=0;i<len;i++)
		{
			if(s[i]=='a') cnt1++;
			else if(s[i]=='v') cnt2++;
			else if(s[i]=='i') cnt3++;
			else if(s[i]=='n') cnt4++;
		}
		len=len*len*len*len;
		int cnt=cnt1*cnt2*cnt3*cnt4;
		cnt1=gcd(cnt,len);
		printf("%d/%d\n",cnt/cnt1,len/cnt1);
	}
}

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
狗题,一开始读错题了,耽误了好久。rng
直接枚举等待的时间,让南北向的车都等待,去判断是否可行。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

const int maxx=5e3+100;
bool vis1[maxx];
bool vis2[maxx];
int a[maxx];
int b[maxx];
int n,m;

int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(vis1,0,sizeof(vis1));
		memset(vis2,0,sizeof(vis2));
		for(int i=1;i<=n;i++) scanf("%d",&a[i]),vis1[a[i]]=1;
		for(int i=1;i<=m;i++) scanf("%d",&b[i]);
		for(int t=0;t<=3008;t++)
		{
			memset(vis2,0,sizeof(vis2));
			for(int i=1;i<=m;i++)
			{
				vis2[b[i]+t]=1;
			}
			int flag=0; 
			for(int i=1;i<=t+100;i++)
			{
				if(vis1[i]&&vis2[i])
				{
					flag=1;
					break;
				}
			}
			if(flag==0)
			{
				printf("%d\n",t);
				break;
			}
		}
	}
}

Rng HDU - 6574
Avin is studying how to synthesize data. Given an integer n, he constructs an interval using the following method: he first generates a integer r between 1 and n (both inclusive) uniform-randomly, and then generates another integer l between 1 and r (both inclusive) uniform-randomly. The interval [l, r] is then constructed. Avin has constructed two intervals using the method above. He asks you what the probability that two intervals intersect is. You should print p* q(−1)(MOD 1, 000, 000, 007), while pq denoting the probability.
Input
Just one line contains the number n (1 ≤ n ≤ 1, 000, 000).
Output
Print the answer.
Sample Input
1
2
Sample Output
1
750000006
其实这个题就是瞎凑数。。。
写了一个求逆元的找出n=2的时候,是3/4。又自己手算了一遍n=3的时候是2/3也就是4/6。在我算n=4的时候,队友猜了一个结论交上去了就过了orz。
代码如下:

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<functional>
#define mod 9973
using namespace std;
typedef long long ll;
char s[100000+10];
long long int sum[100000+10];
ll gcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    ll q=gcd(b,a%b,y,x);
    y-=a/b*x;
    return q;
}
ll cal(ll a,ll b,ll c)
{
    ll x,y;
    ll g=gcd(a,b,x,y);
    if(c%g!=0) return -1;
    x*=c/g;
    b/=g;
    if(b<0) b=-b;
    ll ans=x%b;
    if(ans<=0) ans+=b;
    return ans;
}
ll qsm(ll a,ll b,ll c)
{
	ll ans=1;
	ll res=a%c;
	while(b)
	{
		if(b&1)
			ans*=res,ans%=c;
		res*=res;
		res%=c;
		b>>=1;
	}
	return ans%c;
}
int main ()
{
    ll n;
    while(cin>>n)
    {
    	cout<<((1+n)*cal(2ll*n,1000000007L,1L))%1000000007<<endl;
	}
    return 0;
}

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
水题,但是还是错了一发,(读错题了rng)
代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define ll long long
using namespace std;

const int maxx=1e3+100;
string s;
int n;

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		double ans=0.0;
		int len;
		for(int i=1;i<=n;i++)
		{
			cin>>s;
			len=s.length();
			if(s[len-1]=='0') continue;
			else if(s[len-1]>='5'&&s[len-1]<='9') ans+=0.001*(10-s[len-1]+'0');
			else if(s[len-1]<'5'&&s[len-1]>'0') ans-=0.001*(s[len-1]-'0');
		}
		printf("%.3lf\n",ans);
	}
	return 0;
}

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
提议挺简单的,就是分配工人。但是一开始队友最小公倍数求错了。GG了。多个数的最小公倍数就是先求两个数的最小公倍数,然后再和第三个数求最小公倍数,依次下去。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;

const int maxx=1e3+100;
ll a[maxx];
int n;
ll m;

ll gcd(ll x,ll y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}
int main()
{
	while(scanf("%d%lld",&n,&m)!=EOF)
	{
		for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
		ll temp=a[1]*a[2]/gcd(a[1],a[2]);
		ll cgcd;
		for(int i=3;i<=n;i++)
		{
			cgcd=gcd(temp,a[i]);
			temp=temp*a[i]/cgcd;
		}
		ll sum=0;
		for(int i=1;i<=n;i++) sum+=temp/a[i];
		if(sum>m||m%sum!=0)
		{
			puts("No");
			continue;
		}
		puts("Yes");
		for(int i=1;i<=n;i++)
		{
			printf("%lld",(temp/a[i])*(m/sum));
			if(i!=n) printf(" ");
			else printf("\n"); 
		}
	}
}

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<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
    int x,y;
    cin>>x>>y;
    cout<<(x+y)*(x-y)/4<<endl;
 } 

A题的数据结构题没出出来。补完之后再发。
努力加油a啊,(o)/~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值