2018-2019 ACM-ICPC, Asia East Continent Finals题解

以下所有AC题解程序来自“仙客传奇”团队。


A. Exotic … Ancient City

题解链接:
2018 EC-Final 部分题解 (A,J)
ABCDEFGIJKL CodeForces Gym 102056 简要题解



B. Mysterious … Host

题解链接:
ABCDEFGIJKL CodeForces Gym 102056 简要题解



C. Heretical … Möbius

题解链接:
【中国剩余定理】【技巧】codeforces102056C Heretical … Möbius
Gym - 102056C(2018EC final) - CRT
ABCDEFGIJKL CodeForces Gym 102056 简要题解



D. Deja vu of … Go Players

AC的C++语言程序:

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int n,m;
main()
{
    IO;
    int T;
    cin>>T;
    while(T--){
        cin>>n>>m;
        for(int i=1,x;i<=n;i++){
            cin>>x;
        }
        for(int i=1,x;i<=m;i++){
            cin>>x;
        }
        if(n>m) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}



E. Immortal … Universe

题解链接:
ABCDEFGIJKL CodeForces Gym 102056 简要题解



F. Interstellar … Fantasy

AC的C++语言程序:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

const double pi = acos(-1);
double os, ot, st, os2, ot2, st2;
double r1, r2, ans1, ans2, ans3;
typedef struct node {
	double x, y, z;
} node;
double sqr(double x) { return x * x;}
double calR(double a2, double b2, double c2) { return (acos((a2 + b2 - c2) / (2 * sqrt(a2 * b2))));}
double dis2(node a, node b) { return sqr(a.x - b.x) + sqr(a.y - b.y) + sqr(a.z - b.z); } 

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		node oo;
		double R;
		node s, t;
		scanf("%lf%lf%lf%lf", &oo.x, &oo.y, &oo.z, &R);
		scanf("%lf%lf%lf%lf%lf%lf", &s.x, &s.y, &s.z, &t.x, &t.y, &t.z);

		os2 = dis2(oo, s); ot2 = dis2(oo, t); st2 = dis2(s, t);
		if(st2 == 0) {
			printf("%.8lf\n", 0.0);
			continue;
		}
		os = sqrt(os2); ot = sqrt(ot2); st = sqrt(st2);
		if(calR(ot2, st2, os2) >= pi / 2 || calR(os2, st2, ot2) >= pi/2) {
			printf("%.8lf\n", st);
			continue;
		}
		double R_sot = calR(ot2,os2,st2);
		double h = os * ot * sin(R_sot) / st;
		if(h >= R) {
			printf("%.8lf\n", st);
			continue;
		}
		r1 = acos(R / os);
		r2 = acos(R / ot);
		ans1 = sqrt(os2 - R * R);
		ans2 = sqrt(ot2 - R * R);
		ans3 = R * (R_sot - r1 - r2);
		printf("%.8lf\n",ans1 + ans2 + ans3);
	}
}



G. Omnipotent … Garland

题解链接:
ABCDEFGIJKL CodeForces Gym 102056 简要题解



H. Saintly … Coins



I. Misunderstood … Missing

AC的C++语言程序:

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 101;
int n;
ll dp[2][MAXN][MAXN*MAXN+1];
ll a[MAXN], b[MAXN], c[MAXN];
int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		scanf("%lld", &n);
		for(int i = 1; i <= n; i++)
			scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
		memset(dp, 0, sizeof(dp));
		dp[n & 1][1][n] = a[n];
		for(int i = n - 1; i >= 1; i--) {
			for(int j = 1; j <= n - i; j++) {
				int u = (i + i + j) * (j - 1) / 2 + n, v = (n + n - j + 1) * j / 2;
				for(int k = u; k <= v; k++) {
					dp[i & 1][j + 1][k + i] = max(dp[i & 1][j + 1][k + i], dp[(i + 1) & 1][j][k] + a[i]);
					dp[i & 1][j][k] = max(dp[i & 1][j][k], dp[(i + 1) & 1][j][k] + (k - j * i) * b[i]);
					dp[i & 1][j][k] = max(dp[i & 1][j][k], dp[(i + 1) & 1][j][k] + j * c[i]);
				}
			}
		}
		ll ans = 0;
		for(int j = 1; j <= n; j++)
			for(int k = 1; k <= MAXN * MAXN + 1; k++) ans = max(ans, dp[1][j][k]);
		printf("%lld\n", ans);
	}
}



J. Philosophical … Balance

题解链接:
2018 EC-Final 部分题解 (A,J)
ABCDEFGIJKL CodeForces Gym 102056 简要题解



K. Desperate … Fire Survive

题解链接:
ABCDEFGIJKL CodeForces Gym 102056 简要题解



L. Eventual … Journey

AC的C++语言程序:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
const int MAXN = 100000;
using namespace std;
int lr[MAXN + 5], num[MAXN + 5];
int n, m, nl, nr, nl1, nr1;
int main() {
	cin >> n >> m;
	nl = nr = 0;
	for (int i = 1; i <= n; i++){
		cin >> lr[i];
		if (lr[i]) nl++;
		else nr++;
	}
	for (int i = 1; i <= m; i++){
		int u, v;
		cin >> u >> v;
		if (lr[u] != lr[v]) {
			if (num[u]==0) {
				if (lr[u] == 1) nl1++;
				else nr1++;
			}
			if (num[v]==0){
				if (lr[v] == 1) nl1++;
				else nr1++;
			}
			num[u]++;
			num[v]++;
		}
	}
	for (int i = 1; i <=n;i++){
		int ans = 0;
		if (lr[i] == 1){
			if (num[i] == 0) ans += nl - 1 + nr1 * 2 + (nr - nr1 ) * 3;
			else ans += num[i] + (nl - 1) + 2 * (nr - num[i]);
		} else{
			if (num[i] == 0) ans += nr - 1 + nl1 * 2 + (nl - nl1) * 3;
			else ans += num[i] + (nr - 1) + 2 * (nl - num[i]);
		}
		if (i != n) cout << ans << " ";
		else cout << ans << endl;
	}
	return 0;
}



题解链接:
ABCDEFGIJKL CodeForces Gym 102056 简要题解

猜你喜欢

转载自blog.csdn.net/tigerisland45/article/details/89978207