2018中国大学生程序设计竞赛 - 网络选拔赛(solve5/10)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/passer__/article/details/82077776

题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=55

A题

题意:给你n天,每天你到达一个地方,对于一个地方你可以买可以卖(前提你有东西),问你最后获得的最大的收益是多少,交换的最小次数是多少。

ps:如果没有交换次数跟https://blog.csdn.net/passer__/article/details/82055020就一样了。

思想:如果没有交换次数就贪心搞下,有了交换次数,就用flag标记下是否交换过,保存每组交换的最大的那个即可,最后交换次数等于最大的那个*2;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
	ll valu;
	int flag;
	node(ll a,int b)
	{
		valu=a;
		flag=b;
	}
	friend operator < (node a,node b)
	{
		if(a.valu==b.valu)
			return a.flag<b.flag;
		return a.valu>b.valu; 
	}
};
priority_queue <node> p;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,t;
	ll temp;
	cin>>t;
	ll ans;
	while(t--)
	{
		cin>>n;
		ans=0;
		for(int i=0;i<n;i++)
		{
			cin>>temp;
			if(!p.empty())
			{
				node T=p.top();
				if(T.valu<temp)
				{
					ans=ans+(temp-T.valu);
					p.pop();
					p.push(node(temp,1));
				}
			}
			p.push(node(temp,0));
		}
		int sum=0;
		while(!p.empty())
		{
			node temp=p.top();
			if(temp.flag==1)
				sum++;
			p.pop(); 
		}
		cout<<ans<<" "<<sum*2<<endl;
	}
	return 0;
} 

C题

题意:就是让你重写+和*号的运算,然后让(m+n)^p=m^p+n^p;

通过费马小定理知道a^(p-1)≡1(mod p) 然后两边同时乘a 就变成a^p≡a(mod p)

(m+n)^p=(m%p+n%p)=(m+n)%p   同理乘法(m^p*n^p)=(m%p*n%p)  至于怎么证明一样多不会

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,p;
	cin>>t;
	while(t--)
	{
		cin>>p;
		for(int i=1;i<=p;i++)
		{
			for(int j=1;j<=p;j++)
			{
				printf("%d",(i-1+j-1)%p);
				if(j!=p)
					printf(" ");
			}
			printf("\n");
		}
		for(int i=1;i<=p;i++)
		{
			for(int j=1;j<=p;j++)
			{
				printf("%d",((i-1)*(j-1))%p);
				if(j!=p)
					printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}

D题

题意:问你a^n+b^n=c^n是否成立,成立随意输出一组解,否则-1 -1

思想:费马大定理证明n>2 无解,所以考虑n<=2 

①n=0的时候肯定无解

②n=1 随便自己构造一组解即可

③n==2  通过a^2+b^2=c^2的a值奇偶数列法则 求解 证明:http://tieba.baidu.com/p/108936816

考虑a是奇数还是偶数对应上述2种不同的情况。

cin我T·····

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll t,n,a;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld%lld",&n,&a);
		if(n==0 || n>2)
			printf("-1 -1\n");
		else if(n==1)
			printf("1 %lld\n",a+1ll);	
		else
		{
			if(a%2==1)
			{
				ll temp=(a-1)>>1;
				printf("%lld %lld\n",2ll*temp*temp+2ll*temp,2ll*temp*temp+2ll*temp+1ll);
			}
			else
			{
				ll temp=a>>1;
				printf("%lld %lld\n",temp*temp-1ll,temp*temp+1ll);
			}
		}
	} 
	return 0;
}

I 题

J题

猜你喜欢

转载自blog.csdn.net/passer__/article/details/82077776