牛客网NOIP赛前集训营-普及组(第二场)A,B,C

早上9点起床,打了一波普及组

A

你好诶加币

 自己写的输出是hello, %lld\n忘记 了“ ”只拿了50分难受。

#include<bits/stdc++.h>
#include<limits.h>
using namespace std;
typedef long long ll;
const ll INF=LONG_LONG_MAX;
const ll maxn=9223372036854775807;
const ll minn=LONG_LONG_MIN;
ll a,b;
int main() {
	scanf("%lld%lld",&a,&b);
	if(a>=0&&b<=0||a<=0&&b>=0) {
		printf("%lld",a+b);
		return 0;
	} else {
		if(a<=0&&b<=0) {
			if(a>b) swap(a,b);

			ll temp=minn-a;
			if(temp<=b) {
				printf("%lld",a+b);
			} else {
				printf("\"hello, %%lld\\n\"");
			}

		} else {
			if(a<b) swap(a,b);
			ll temp=maxn-a;
			if(temp>=b) {
				printf("%lld",a+b);
			} else {
				printf("\"hello, %%lld\\n\"");
			}
		}
	}
	return 0;
}

B

最后一次

#include<bits/stdc++.h>
#include<limits.h>
using namespace std;
typedef long long ll;
const ll INF=LONG_LONG_MAX;
//const ll maxn=;
ll n;
bool prime(ll num) {
	if(num==2 || num==3) {
		return true;
	}
	//不在6的倍数两侧的一定不是素数
	if(num%6!=1 && num%6!=5) {
		return false;
	}
	ll tmp = (ll) sqrt(num);//获取平方根
	//在6的倍数两侧的也可能不是素数
	for(ll i=5; i<=tmp; i+=6) {
		if(num%i==0 || num%(i+2)==0) {
			return false;
		}
	}
	return true;
}
int main() {
	scanf("%lld",&n);
	for(ll i=n; i>1; --i) {
		if(prime(i)) {
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

C

选择颜色

先贴代码




#include<bits/stdc++.h>
#include<limits.h>
using namespace std;
typedef long long ll;
const ll INF=LONG_LONG_MAX; 
const ll mod=10007;
ll n,c;
ll my_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1){
			res=res*x%mod;
		}
		x=x*x%mod;
		n=n>>1;
	}
	return res%mod;
}
int main()
{
	scanf("%lld%lld",&n,&c);
	int ans=my_pow(c-1,n);
	if(n%2==1) (ans-=(c-1))%=mod;
	else if(n%2==0) (ans+=(c-1))%=mod;
	printf("%d",ans);
	return 0;
} 

An代表由n个人构成的环的染色方案 

最后通项公式的推到用了特征根法;

 

猜你喜欢

转载自blog.csdn.net/TDD_Master/article/details/82713671