2017 Multi-University Training Contest - Team 2

1001

题意:给出一个n, a, b,代表有n道题, Derek and Alfia 的得分,然后出给 Derek and Alfia 作答序列,每道题只包含ABC三个答案,问是否存在一种答案序列使得 Derek and Alfia 的得分恰好等于a和b

思路:统计出 Derek and Alfia 统一道题答案相同的次数x,然后y是作答答案不相同的题目个数,然后YY一下

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define ft first
#define sd second
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 80000 + 10;
char st[qq], mt[qq];

int main(){
	int t;	scanf("%d", &t);
	while(t--) {
		int n, a, b;	scanf("%d%d%d", &n, &a, &b);
		scanf("%s%s", st, mt);
		int len = strlen(st);
		int cnt = 0;
		for(int i = 0; i < n; ++i) {
			if(st[i] == mt[i])	cnt++;
		}
		int x = cnt, y = n - cnt;
		int tmp = min(x, min(a, b));
		a -= tmp, b -= tmp;
		if(y >= a + b) {
			puts("Not lying");
		} else {
			puts("Lying");
		}
	}
	return 0;
}



1003

题意:给出序列a,和序列b,然后要求an + 1 到 a2n,从an + 1开始求一直求到a2n,对于每个ai,你可以在b数组中选一个数那么你可以这个ai可以小于等于aj - j (bk <= j < i)

求出最大和

思路:如果b数组是n的全排列,那么b数组其实是没有用的,但这题不是,b数组中的数值有重复的,那么实际上我们从大到小贪心即可,dp[i]代表从i位置开始一直到n位置中ai - i的最大值,对于每次更新的ai我们用一个maxn记录an + 1 到 i的最大值,那么每次贪心的时候就是maxn 和 dp[i]中选一个即可

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define ft first
#define sd second
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 250000 + 10;
const int MOD = 1e9 + 7;
LL dp[qq], num[qq], b[qq];
LL maxn;
int n;
bool cmp(int x, int y) {
	if(dp[x] == dp[y])	return 0;
	return dp[x] < dp[y];
}

int main(){
	while(scanf("%d", &n) != EOF) {
		for(int i = 1; i <= n; ++i) {
			scanf("%lld", num + i);
			num[i] = num[i] - i;
		}
		for(int i = 1; i <= n; ++i) {
			scanf("%lld", b + i);
		}
		dp[n + 1] = 0;
		for(int i = n; i >= 1; --i) {
			dp[i] = max(dp[i + 1], num[i]);
		}
		sort(b + 1, b + 1 + n, cmp);
		maxn = 0;
		LL ans = 0;
		LL cnt = n + 1;
		for(int i = n; i >= 1; --i, cnt++) {
			LL tmp = max(maxn, dp[b[i]]);
			ans = (ans + tmp) % MOD;
			maxn = max(maxn, tmp - cnt);
		}
		printf("%lld\n", ans % MOD);
	}
	return 0;
}

1004

队友之前课设做过关于拼图的恰好有这个结论存在

就是求拼图序列的逆序数即可,为偶就可以拼出来,否则不可以

对于这里如何构造序列,其实这里不用构造...

只需要算出逆序数

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
typedef long long LL;
int main() {
    int t,n,m,p;
    scanf("%d",&t);
    while(t--) {
        scanf("%d%d%d",&n,&m,&p);
        int ans=0;
        int cnt=n*m-1,cnt1=n*m-1,top=1;
        while(1) {
            if(top>cnt) break;
            cnt1--;
            top++;
            int pp=1;
            for(int i=1;;i++) {
                pp=pp+p-1;
                if(pp>cnt1) break;
                ans=(ans+pp-1)%2;
                cnt1--;
                top++;
            }
        }
        if(!ans) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

1009

题意:给出一个a序列,然后你需要构造一个b序列,1 <= bi <= ai,要求b序列中任意区间的gcd都要 >= 2,问有多少种b序列满足条件

思路:之前做过一个求一个序列中gcd = 1的子序列有多少个的题

来自:传送门

仔细想想其实和这题有一点点类似,但是求解方法是不一样的、

比赛中没有想出来,最后参考了 传送门  这位聚聚的方法才知道做法、

关于莫比乌斯反演:传送门

其实最终的方法还是容斥,但关键就关键在如何容斥、这为聚聚的方法已经讲得很明白了,就不赘述了、

#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define ft first
#define sd second
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
bool isprime[qq];
int num[qq], prime[qq], cnt = 0;
int mu[qq];
void Init() {
	for(int i = 2; i < qq; ++i) {
		if(!isprime[i]) {
			prime[cnt++] = i;
			mu[i] = -1;
		}
		for(int j = 0; j < cnt && i * prime[j] < qq; ++j) {
			isprime[i * prime[j]] = true;
			if(i % prime[j]) {
				mu[i * prime[j]] = -mu[i];
			} else {
				mu[i * prime[j]] = 0;
				break;
			}
		}
	}
}
LL QuickPow(LL a, LL b) {
	LL ans = 1;
	while(b > 0) {
		if(b & 1)	ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}
int maxn, minx, n;
LL Solve() {
	for(int i = 2; i <= maxn; ++i) {
		num[i] += num[i - 1];
	}
	LL ans = 0;
	for(int i = 2; i <= minx; ++i) if(mu[i]) {
		LL tmp = -mu[i];
		int m = maxn / i;
		for(int j = 1; j <= m; ++j) {
			int l = i * j, r = min(i * j + i - 1, maxn);
			tmp = (tmp * QuickPow(j, num[r] - num[l - 1])) % MOD;
		}
		ans = (ans + tmp) % MOD;
	}
	return (ans % MOD + MOD) % MOD;
}

int main(){
	Init();
	int T, Cas = 0;
	scanf("%d", &T);
	while(T--) {
		scanf("%d", &n);
		mst(num, 0);
		maxn = -INF, minx = INF;
		for(int i = 0; i < n; ++i) {
			int x;	scanf("%d", &x);
			num[x]++;
			maxn = max(maxn, x), minx = min(minx, x);
		}
		printf("Case #%d: %lld\n", ++Cas, Solve());
	}
	return 0;
}






1011

题意:给出n个整点的坐标,问可以构成多少个正多边形

思路:可知在平面上整点的正多边形只有正方形,然后枚举下就好了,注意考虑斜着的正方形

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <string>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define ft first
#define sd second
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 400 + 10;
const int MOD = 1e9 + 7;
bool vis[qq][qq];
pill p[qq + 100];
int n;

int main(){
	while(scanf("%d", &n) != EOF) {
		mst(vis, false);
		for(int x, y, i = 0; i < n; ++i) {
			scanf("%d%d", &x, &y);
			vis[x + 100][y + 100] = true;
			p[i] = mk(x + 100, y + 100);
		}
		int cnt = 0;
		for(int l = 1; l <= 200; ++l) {
			for(int i = 0; i + l <= 200; ++i) {
				for(int j = 0; j + l <= 200; ++j) {
					if(vis[i][j] && vis[i + l][j] && vis[i][j + l] && vis[i + l][j + l]) {
						cnt++;
					}
				}
			}
		}
		sort(p, p + n);
		for(int i = 0; i < n; ++i) {
			for(int y = 1; p[i].ft + y <= 200; ++y) {
				for(int x = 1; p[i].sd + x <= 200; ++x) {
					int a = p[i].ft;
					int b = p[i].sd;
					if(a - x >= 0 && b + x + y <= 200 && vis[a - x][b + y] && vis[a + y][b + x] && vis[a - x + y][b + x + y]) {
						cnt++;
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值