2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest题解

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


A. Xu Xiake in Henan Province

AC的C++语言程序:

#include<iostream>
#include<string>
using namespace std;
string ans[]={"Typically Otaku",
"Eye-opener",
"Young Traveller",
"Excellent Traveller",
"Contemporary Xu Xiake"};
int main()
{
    int T;
    cin>>T;
    while(T--){
        int a[4],s=0;
        for(int i=0;i<4;i++){
            cin>>a[i];
            if(a[i]) s++;
        }
        cout<<ans[s]<<endl;
    }
}

AC的C++语言程序:

#include <iostream>

using namespace std;

int main(void) {
    int cnt, x;
    int t;
    scanf("%d", &t);
    while (t--) {
        cnt = 0;
        for (int i = 0; i < 4; i++) {
            scanf("%d", &x);
            if (x) cnt++;
        }
        if (cnt == 0) printf("Typically Otaku\n");
        else if (cnt == 1) printf("Eye-opener\n");
        else if (cnt == 2) printf("Young Traveller\n");
        else if (cnt == 3) printf("Excellent Traveller\n");
        else if (cnt == 4) printf("Contemporary Xu Xiake\n");
    }
    return 0;
}

B. Ultraman vs. Aodzilla and Bodzilla

题解链接:
【数学思维】【分类】codeforces102028B Ultraman vs. Aodzilla and Bodzilla
A-L CodeForces Gym 102028 简要题解
BCH 2018-2019 ACM-ICPC 焦作赛区 部分题解

C. Supreme Command

题解链接:
Gym 102028C - Supreme Command - [思维题][2018-2019 ACM-ICPC Asia Jiaozuo Regional Contest Problem C]
A-L CodeForces Gym 102028 简要题解
BCH 2018-2019 ACM-ICPC 焦作赛区 部分题解


D. Keiichi Tsuchiya the Drift King

AC的C++语言程序:

#include<bits/stdc++.h>
using namespace std;
const double eps=1e-1;
const double Pi=acos(-1.0);
int main()
{
    double a,b,r,d;
    int T;
    cin>>T;
    while(T--){
        cin>>a>>b>>r>>d;
        double ang=atan((a+r)/b);
        d=(d*Pi)/180;
        if(2*(d+ang)>=Pi) {
            printf("%.12f\n",sqrt(b*b+(a+r)*(a+r))-r);
        }else
        {
            ang=sin(d+ang);
            printf("%.12f\n",sqrt(b*b+(a+r)*(a+r))*ang-r);
        }
    }
}

AC的C++语言程序:

扫描二维码关注公众号,回复: 6198994 查看本文章
#include <iostream>
#include <cmath>

using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-14;

inline int fixCmp(double a, double b) {
    if (fabs(a - b) <= EPS) return 0;
    else if (a > b) return 1;
    return -1;
}

int main(void) {
    int t;
    double a, b, r, d;
    scanf("%d", &t);
    while (t--) {
        scanf("%lf%lf%lf%lf", &a, &b, &r, &d);
        double theta = d * PI / 180;
        double bound = -atan((a + r) / b);
        while (fixCmp(bound, 0) < 0) bound += PI / 2;
        if (fixCmp(theta, bound) >= 0) {
            printf("%.12f\n", sqrt((a + r) * (a + r) + b * b) - r);
        } else {
            printf("%.12f\n", b * sin(theta) + (a + r) * cos(theta) - r);
        }
    }
    return 0;
}

E. Resistors in Parallel

AC的Java语言程序:

import java.util.Scanner;
import java.math.BigInteger;
public class Main{
     static int prime[];
     static boolean table[];
     static final int maxn=1000;
     public static void main(String []args){
        Scanner in=new Scanner(System.in);
        int cnt=0;
        prime=new int[maxn];
        table=new boolean[maxn];
        for(int i=2;i<maxn;i++){
            if(!table[i]){
                prime[cnt++]=i;
                for(int j=2;i*j<maxn;j++)
                table[i*j]=true;
            }
        }
        BigInteger n,a,b,g;
        int T;
        T=in.nextInt();
        for(int s=0;s<T;s++){
            n=in.nextBigInteger();
            a=BigInteger.valueOf(1);
            b=BigInteger.valueOf(1);
            int num=0;
            while(true){
                a=a.multiply(BigInteger.valueOf(prime[num++]));
                if(a.compareTo(n)>0) break;
            }
            a=a.divide(BigInteger.valueOf(prime[--num]));
            for(int i=0;i<num;i++){
                b=b.multiply(BigInteger.valueOf(prime[i]*prime[i]-1));
                b=b.divide(BigInteger.valueOf(prime[i]-1));
            }
            g=a.gcd(b);
            System.out.println(a.divide(g)+"/"+b.divide(g));
        }
     }
}

AC的Java语言程序:

import java.util.Scanner;
import java.math.BigInteger;

public class Main {
    private static int prime[];
    private static boolean notPrime[];
    private final static int LIM = 10000;
    private static int cur = 0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // build prime table
        notPrime = new boolean[LIM];
        prime = new int[LIM];
        for (int i = 2; i < LIM; i++) {
            if (!notPrime[i]) prime[cur++] = i;
            for (int j = 0; j < cur; j++) {
                int tmp = prime[j] * i;
                if (tmp >= LIM) break;
                notPrime[tmp] = true;
                if (i % prime[j] == 0) break;
            }
        }
        // cnt
        int t;
        BigInteger n;
        t = in.nextInt();
        for (int k = 0; k < t; k++) {
            n = in.nextBigInteger();
            BigInteger mx = BigInteger.valueOf(1), crt = BigInteger.valueOf(1);
            for (int i = 0; i < cur; i++) {
                BigInteger tmp = mx.multiply(BigInteger.valueOf(prime[i]));
                if (tmp.compareTo(n) > 0) break;
                crt = crt.add(crt.multiply(BigInteger.valueOf(prime[i])));
                mx = tmp;
            }
            BigInteger g = mx.gcd(crt);
            System.out.println(mx.divide(g) + "/" + crt.divide(g));
        }
    }
}

F. Honeycomb

AC的C++语言程序:

#include<bits/stdc++.h>
using namespace std;
const int maxn=10000+5;
int dx[]={-1,-1,1,1,-2,2};
int dy[]={-3,3,-3,3,0,0};
char gird[maxn][maxn];
int r,c;
bool vis[maxn][maxn];
struct Node
{
    int x,y,step;
};
Node str,ter;
int bfs()
{
    vis[str.x][str.y]=1;
    Node first=str,u,v;
    first.step=1;
    queue<Node> q;
    q.push(first);
    while(!q.empty()){
        u=q.front();q.pop();
        if(u.x==ter.x&&u.y==ter.y) return u.step;
        int dr,dc;
        for(int i=0;i<6;i++){
            dr=u.x+dx[i],dc=u.y+dy[i];
            if(gird[dr][dc]=='/'||gird[dr][dc]=='\\'||gird[dr][dc]=='-'||vis[dr+dx[i]][dc+dy[i]]) continue;
            v.x=dr+dx[i],v.y=dc+dy[i];
            v.step=u.step+1;
            q.push(v);
            vis[v.x][v.y]=1;
        }
    }
    return -1;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&r,&c);
        r=4*r+3,c=6*c+3;
        getchar();
        for(int i=0;i<r;i++){
            gets(gird[i]);
            for(int j=0;j<c;j++){
                if(gird[i][j]=='S') str.x=i,str.y=j;
                if(gird[i][j]=='T') ter.x=i,ter.y=j;
                vis[i][j]=false;
            }
        }
        printf("%d\n",bfs());
    }
}

AC的C++语言程序:

#include <iostream>
#include <queue>

using namespace std;
const int LIM = 1e3;

char dat[5 * LIM][7 * LIM];
int vis[5 * LIM][7 * LIM];
int rbound, down;
int t, r, c, stamp;
int sr, sc, tr, tc;
const int dr[] = {-2, 2, -1, -1, 1, 1};
const int dc[] = {0, 0, 3, -3, 3, -3};
struct Node {
    int cnt, r, c;
    Node(int nr = 0, int nc = 0, int ncnt = 0) {
        cnt = ncnt, r = nr, c = nc;
    }
};

int bfs() {
    Node crt;
    crt.cnt = 1;
    crt.r = sr;
    crt.c = sc;
    queue<Node> q;
    q.push(crt);
    while (!q.empty()) {
        crt = q.front();
        q.pop();
        if (dat[crt.r][crt.c] == 'T') return crt.cnt;
        for (int i = 0; i < 6; i++) {
            int nr = crt.r + dr[i];
            int nc = crt.c + dc[i];
            if (nr >= 0 && nr < down && nc >= 0 && nc < rbound
                && dat[nr][nc] == ' ' && vis[nr][nc] != stamp) {
                vis[nr][nc] = stamp;
                nr += dr[i], nc += dc[i];
                if (nr >= 0 && nr < down && nc >= 0 && nc < rbound
                    && vis[nr][nc] != stamp) {
                    vis[nr][nc] = stamp;
                    q.push(Node(nr, nc, crt.cnt + 1));
                }
            }
        }
    }
    return -1;
}

inline void gl(char *cur) {
    char ch;
    while ((ch = getchar()) != '\n') *(cur++) = ch;
}

int main(void) {
    scanf("%d", &t);
    for (stamp = 1; stamp <= t; stamp++) {
        scanf("%d%d", &r, &c);
        gl(dat[0]);
        for (int i = 0; i < r * 4 + 3; i++)
            gl(dat[i]);
        down = r * 4 + 3;
        rbound = 6 * c + 3;
        for (int i = 0; i < down; i++) {
            for (int j = 0; j < rbound; j++) {
                if (dat[i][j] == 'S')
                    sr = i, sc = j;
                else if (dat[i][j] == 'T')
                    tr = i, tc = j;
            }
        }
        printf("%d\n", bfs());
        // destroy S and T
        dat[sr][sc] = ' ';
        dat[tr][tc] = ' ';
    }
    return 0;
}

G. Shortest Paths on Random Forests

题解链接:
A-L CodeForces Gym 102028 简要题解


H. Can You Solve the Harder Problem?

题解链接:
A-L CodeForces Gym 102028 简要题解
BCH 2018-2019 ACM-ICPC 焦作赛区 部分题解


I. Distance

AC的C++语言程序:

#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
ll p[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int t,n,d;
	ll  ans,tmp;
	
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(int i = 2;i <= n;++i)
		{
			cin>>d;
			p[i] = p[i - 1] + d;
		}
		
		int l = 1,r = n + 1;
		ans = 0,tmp = 0;
		cout<<"0";
		for(int i = 1;i < n;++i)
		{
			if(i & 1)
			{	
				tmp += p[--r] - p[l];
				ans += tmp;
			}
			else
			{
				++l;
				ans += tmp; 
			}
			cout<<' '<<ans;	
		}
		cout<<endl;
	}
	
	return 0;
}

AC的C++语言程序:

#include <iostream>

using namespace std;

typedef long long LL;

const LL LIM = 1e6;
LL dat[LIM];

int main(void) {
    LL t, n, tmp, ans;
    scanf("%lld", &t);
    while (t--) {
        scanf("%lld", &n);
        LL cur = 0;
        dat[cur++] = 0;
        for (LL i = 1; i < n; i++) {
            scanf("%lld", &tmp);
            dat[cur] = dat[cur - 1] + tmp;
            cur++;
        }
        LL left = 0, right = cur;
        printf("0");
        ans = tmp = 0;
        for (LL i = 1; i < n; i++) {
            if (i & 1) {
                ans += tmp;
                ans += dat[--right] - dat[left];
                tmp += dat[right] - dat[left];
            } else {
                ans += tmp;
                left++;
            }
            printf(" %lld", ans);
        }
        putchar('\n');
    }
    return 0;
}

AC的C++语言程序:

#include<bits/stdc++.h>

using namespace std;

const int maxn=1e5+5;

typedef long long ll;

ll a[maxn];

int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        ll sum=0;
        scanf("%d",&n);
        for(int i=1;i<n;i++){
            scanf("%lld",&a[i]);
            sum+=a[i];
        }
        ll tt=0,tmp=0;
        int l=1,r=n-1;
        for(int i=1;i<=n;i++){
            if(i&1){
                tmp+=tt;
            }else{
                tt+=sum;
                sum-=a[l];
                l++;
                sum-=a[r];
                r--;
                tmp+=tt;
            }
            if(i==1){
                printf("%lld",tmp);
            }else{
                printf(" %lld",tmp);
            }
        }
        printf("\n");
    }
    return 0;
}

J. Carpets Removal

题解链接:
Gym102028J
A-L CodeForces Gym 102028 简要题解


K. Counting Failures on a Trie

题解链接:
A-L CodeForces Gym 102028 简要题解


L. Connected Subgraphs

题解链接:
A-L CodeForces Gym 102028 简要题解



题解连接:
ADEFI CodeForces GYM 102028 2018-2019 ACM-ICPC, Asia Jiaozuo Regional Contest
A-L CodeForces Gym 102028 简要题解
BCH 2018-2019 ACM-ICPC 焦作赛区 部分题解

猜你喜欢

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