1. 程式人生 > >2017 CCPC 湘潭邀請賽

2017 CCPC 湘潭邀請賽

三元 三元組 pre fine hellip ont putchar calc -i

Problem A

Problem B

Problem C

Problem D

直接輸出即可。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)

const int N = 1e2 + 10;

int c[N][N], f[N][N];
int n, m, a, b;


int main(){

	while (~scanf("%d%d%d%d", &n, &m, &a, &b)){
		rep(i, 1, n){
			rep(j, 1, m) scanf("%1d", c[i] + j);
		}

		rep(i, 1, n * a){
			rep(j, 1, m * b){
				int x = (i - 1) / a + 1;
				int y = (j - 1) / b + 1;
				printf("%d", c[x][y]);
			}
			putchar(10);
		}
	}

	return 0;
}

  

Problem E

Problem F

首先可以肯定的是 $f_{0} + f_{1} + f_{2} + f_{3} = m^{3}$

那麽計算出其中的$3$個就可以得到剩余的$1$個。

顯然$f_{0}$和$f_{3}$是比較好求的。

所以$f_{1}$和$f_{2}$求出一個,問題就解決了。

大概是……$f_{2}$比較好求?

求$f_{3}$的時候記錄一下有哪些三元組是符合這個條件的。

首先枚舉兩個數,把他們放在$(1, 2)$,$(1, 3)$,$(2, 3)$的位置,然後枚舉剩下那個數可以是什麽。

首先在$a[]$中沒有出現的並且在$[1, m]$中的數肯定可以放,這個直接單獨計算。

枚舉在$a[]$中出現過的數,得到一個新的三元組,根據題意這個三元組要麽計入$f_{2}$要麽計入$f_{3}$。

那麽看一下是否計入了$f_{3}$,如果不在就計入$f_{2}$

坑點:可能出現$a_{i} > m$的情況。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)

typedef long long LL;

const int N = 2e2 + 10;
const int M = 1e7 + 10;

LL f0, f1, f2, f3;
bitset <M> c, d, f;
int n, nn, m;
int tot;
int a[N], b[N];

void calc_f0(){
	rep(i, 1, n) b[i] = a[i];
	sort(b + 1, b + n + 1);

	int cnt = unique(b + 1, b + n + 1) - b - 1;
	tot = cnt;
	rep(i, 1, n) a[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b;
	f0 = 0ll + m - cnt;
	f0 = 1ll * f0 * f0 * f0;
}

void calc_f1(){
	f1 = 1ll * m * m * m - f0 - f2 - f3;
}

void calc_f2(){

	f2 = 0;
	d.reset();
	f.reset();

	rep(i, 1, n - 1){
		rep(j, i + 1, n){
			int x = a[i] * tot + a[j];
			if (d[x]) continue;
			d.set(x);
			f2 += 0ll + m - tot;
			rep(k, 1, tot){
				int y = a[i] * tot * tot + a[j] * tot + k;
				if (!c[y]) f.set(y);
			}	
		}
	}

	d.reset();

	rep(i, 1, n - 1){
		rep(j, i + 1, n){
			int x = a[i] * tot + a[j];
			if (d[x]) continue;
			d.set(x);
			f2 += 0ll + m - tot;
			rep(k, 1, tot){
				int y = k * tot * tot + a[i] * tot + a[j];
				if (!c[y]) f.set(y);
			}
		}
	}

	d.reset();

	rep(i, 1, n - 1){
		rep(j, i + 1, n){
			int x = a[i] * tot + a[j];
			if (d[x]) continue;
			d.set(x);
			f2 += 0ll + m - tot;
			rep(k, 1, tot){
				int y = a[i] * tot * tot + k * tot + a[j];
				if (!c[y]) f.set(y);
			}
		}
	}

	f2 += 0ll + f.count();
}

void calc_f3(){
	int cnt = 0;
	c.reset();
	rep(i, 1, n - 2){
		rep(j, i + 1, n - 1){
			rep(k, j + 1, n){
				int x = a[i] * tot * tot + a[j] * tot + a[k];
				c.set(x);
			}
		}
	}

	f3 = c.count();
}

int main(){

	while (~scanf("%d%d", &n, &m)){
		nn = n;
		n  = 0;
		rep(i, 1, nn){
			int x;
			scanf("%d", &x);
			if (x >= 1 && x <= m) a[++n] = x;
		}
			
		calc_f0();
		calc_f3();
		calc_f2();
		calc_f1();

		printf("%lld %lld %lld %lld\n", f0, f1, f2, f3);
	}

	return 0;
}

  

Problem G

Problem H

Problem I

Problem J

2017 CCPC 湘潭邀請賽