2020 HZNU Winter Training Day 10 AE题解

2020 HZNU Winter Training Day 10 AE题解

E: Molly’s Chemicals CodeForces - 776C

题意:给出n个数和一个数k,问有多少个区间满足区间和等于k的幂。
思路:由题目给出的范围可以知道k的幂最大不超过1e15,这题很容易想到前缀和,但是暴力公式是sum[i] - sum[j] = kt 显然会t,公式可以转化为变成sum[j] = sum[i] - kt,那么可以用map类型的数组记录到每一个前缀和sum[i],map返回的值即sum[i]-k^t的个数。具体代码比较好理解。
代码:

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
const int maxn=1e6+9;
const int N=1<<20;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
const int temp=233;
const double eps=0.000001;
const double PI=acos(-1);
const int dx[] = {0,0,1,1,1,-1,-1,-1};
const int dy[] = {-1,1,1,-1,0,1,-1,0};
inline int read(){
    int num=0, w=0;char ch=0;
    while (!isdigit(ch)) {w|=ch=='-';ch = getchar();}
    while (isdigit(ch)) {num = (num<<3) + (num<<1) + (ch^48);ch = getchar();}return w? -num: num;
}
int n,k;
int a[maxn];
ll suma[maxn];
map<ll,ll> mp;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		suma[i]=suma[i-1]+a[i];
	}
	ll t=1,ans=0;
	while(abs(t)<1e15){
		mp.clear();
		mp[0]=1;
		for(int i=1;i<=n;i++){
			ans+=mp[suma[i]-t];
			mp[suma[i]]++;
		}
		t*=k;
		if(t==1) break;
	}
	printf("%lld\n",ans);
	return 0;
}

A:Infinite Fence CodeForces - 1260C

题意:现有10100块木板需要涂漆,第x块如果是x是a的倍数,则涂红颜色,是b的倍数,则涂蓝颜色。如果既是a又是b的倍数,那么两种颜色都可以涂;如果连续有k块板的颜色是一样的,则被处死输出REBEL,否则输出OBEY。问是否能避免被处死。我们肯定优先使不被处死。
思路:假设r,b互质且人r 代码:

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
const int maxn=1e6+9;
const int N=1<<20;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
const int temp=233;
const double eps=0.000001;
const double PI=acos(-1);
const int dx[] = {0,0,1,1,1,-1,-1,-1};
const int dy[] = {-1,1,1,-1,0,1,-1,0};
inline int read(){
    int num=0, w=0;char ch=0;
    while (!isdigit(ch)) {w|=ch=='-';ch = getchar();}
    while (isdigit(ch)) {num = (num<<3) + (num<<1) + (ch^48);ch = getchar();}return w? -num: num;
}
int t,n,m;
ll r,b,k;
int main(){
	t=read();
	while(t--){
		scanf("%lld%lld%lld",&r,&b,&k);
		if(r>b) swap(r,b);
		ll g=(ll)__gcd(b,r);
		r/=g;
		b/=g;
		if(ll(k-1)*r+1<b) printf("REBEL\n");
		else printf("OBEY\n");
	}
  	return 0;
}

你可能感兴趣的:(2020 HZNU Winter Training Day 10 AE题解)