codechef April Challenge 2018 Div2(1-4)

2018-06-17 20:38:55来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

T1

签到题,两种情况分别计算然后取个min

#include<vector>
#include<map>
#include<cstdio>
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x < y ? y : x)
#define abs(x) (x < 0 ? - x : x)
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9'){if(c == '-') f = -1;  c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N;
int a[MAXN];
int x = INF, y = INF, z = INF;
int main() {
	#ifdef WIN32
	freopen("a.in", "r", stdin);
	#endif
	N = read();
	for(int i = 1; i <= N; i++) a[i] = read();
	for(int i = 1; i <= N; i++) {
		int opt = read();
		if(opt == 1) x = min(x, a[i]);
		else if(opt == 2) y = min(y, a[i]);
		else if(opt == 3) z = min(z, a[i]);
	}
	printf("%d", min(x + y, z));
	return 0; 
} 

T2

不会QWQ....

首先一个很显然的性质就是当$w >8$或$w < -9$的时候是无解的

否则,我们令$D_1=x$,$D_N = x +W$,这样其它的数就可以任意取了,有$10^{N - 2}$种方案

然后把$x$的取值乘上

具体见代码吧

#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define LL long long 
using namespace __gnu_pbds;
using namespace std;
const LL MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
inline LL read() {
	char c = getchar(); LL x = 0, f = 1;
	while(c < '0' || c > '9'){if(c == '-') f = -1;  c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
LL T, N, W;
LL fastpow(LL a, LL p) {
	LL base = 1;
	while(p) {
		if(p & 1) base = (base * a) % mod;
		p >>= 1; a = (a * a ) % mod;
	}
	return base % mod;
}
main() {
	#ifdef WIN32
	freopen("a.in", "r", stdin);
	//freopen("b.out", "w", stdout);
	#endif
	T = read();
	while(T--) {
		N = read(), W = read();
		if(W > 8 || W < -9 ) {printf("0\n"); continue;}	
		printf("%lld\n", (W >= 0 ? (9 - W) * fastpow(10, N - 2) : (10 + W) * fastpow(10, N - 2) ) % mod); 
	}
}  

  

T3

考虑到值域很小,首先预处理出每个值的出现次数

然后枚举所有值,再枚举一个断点,根据这个数拆开后的两个数的出现次数算贡献

两个数相同的时候需要特判

存值域可以让每个数加上下界,也可以直接用cc_hash_table,可以卡过

#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x < y ? y : x)
#define abs(x) (x < 0 ? - x : x)
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define int long long 
 
using namespace __gnu_pbds;
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9'){if(c == '-') f = -1;  c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int T, N;
int a[MAXN];
 
cc_hash_table<int,int>vis;
cc_hash_table<int,bool>happen;
main() {
	#ifdef WIN32
	freopen("a.in", "r", stdin);
	#endif
	T = read(); 
	while(T--) {
		N = read();
		int mx = -INF, mi = INF; vis.clear(); happen.clear();
		for(int i = 1; i <= N; i++) a[i] = read(), mx = max(a[i], mx), mi = min(a[i], mi);
		for(int i = 1; i <= N; i++)
			vis[a[i]]++;
		int ans = 0;
		for(int i = 1; i <= N; i++) {
			int limit = 2 * a[i];
			if(happen[limit]) continue;
			for(int j = mi; j <= mx; j++) {
				if(vis[j] && vis[limit - j]) {
					if(j == (limit - j)) ans += (vis[j] - 1) * vis[j];
					else ans += vis[j] * vis[limit - j];
				}
			}
			happen[limit] = 1;
		}
		printf("%lld\n", ans / 2);
	}
}  

  

T4

没啥可说的

大力特判,细节巨多

#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long 
using namespace __gnu_pbds;
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9'){if(c == '-') f = -1;  c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int T, N;
char s[MAXN];
int a[MAXN], b[MAXN];
main() {
	#ifdef WIN32
	freopen("a.in", "r", stdin);
	freopen("b.out", "w", stdout);
	#endif
	scanf("%d", &T);
	while(T--) {
		scanf("%s", s + 1); scanf("%d", &N);
		int L = strlen(s + 1);
		for(int i = 1; i <= L; i++) 
			a[i] = a[i - 1], b[i] = b[i - 1], s[i] == 'a' ? a[i]++ : b[i]++;
		int ans = 0;
		if(a[L] > b[L]) {
			for(int i = 1; i <= L; i++) {
				if(a[i] > b[i]) ans = ans + N;
				else if(a[i] == b[i]) ans = ans + N - 1;
				else {
					ans = ans + max((int)0, N - 1 - (b[i] - a[i]) / (a[L] - b[L])); 
				}
			}	
		} 
		else if(a[L] == b[L]) {
			for(int i = 1; i <= L; i++) {
				if(a[i] > b[i]) ans = ans + N;
				else continue; 
			}
		}
		else {
			for(int i = 1; i <= L; i++) {
				if(a[i] > b[i]) 
					ans = ans + min(N, (a[i] - b[i]) / (b[L] - a[L]) + (bool)((a[i] - b[i]) % (b[L] - a[L])));
				else continue;
			}	
		}
		printf("%lld\n", ans);
	}
}  

  

剩下的还没做

等APIO结束再说吧(估计也做不动了)

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:利用GDI+处理图像的色彩

下一篇:模板——STL队列