2018 ACM 国际大学生程序设计竞赛上海大都会部分题解

题目链接

2018 ACM 国际大学生程序设计竞赛上海大都会
下午午休起床被同学叫去打比赛233
然后已经过了2.5h了
先挑过得多的做了
....

A题

rand x*n 次点,每次judge一个点位端点的共线向量数判断是否大于给定x
强行rand 500次

代码

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x = 0,f = 1;
    char c = getchar();
    while(c < '0' || c > '9') {if(c == '-')f =- 1;  c = getchar(); }
    while(c <= '9' &&c >= '0') x = x * 10 + c - '0',c = getchar();
    return x * f;
}
const int maxn = 20007;
#define eps (1e-13)
double k;
int n;
struct points {
    int x,y;
} p[maxn];
bool solve(int p1,int p2) {
    int tx = p[p1].x - p[p2].x,ty = p[p1].y - p[p2].y;
    int cnt = 2;
    for(int i = 1;i <= n;++ i) {
        if(i == p1 || i == p2) continue;
        int px = p[p1].x - p[i].x,py = p[p1].y - p[i].y;
        if((long long)tx * py - (long long)ty * px == 0) cnt ++;
    }
    double K = (double) cnt /  (double) n;
    return (K >= k);
}
int main() {
    srand(time(0));
    srand(rand());
    int t = read();
    while(t -- ) {
        n = read(); scanf("%lf",&k);
        for(int i = 1;i <= n;++ i) p[i].x = read(),p[i].y = read();
        int p1,p2;
        bool flag = false;
        for(int i = 500;i --;) {
            p1 = rand() % n + 1;
            p2 = p1;
            while(p2 == p1) p2 = rand() % n + 1;
            if(solve(p1,p2)) {
                flag = true; break;
            }
            if(flag) break;
        }
        if(t != 0) {
            if(flag) puts("Yes");
            else puts("No");
        }
        if(t == 0) {
            if(flag)printf("Yes");
            else printf("No");
        }
    }
    return 0;
}

B题

很sb的打了nlogn筛

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 200000;
vector<int>vec[maxn + 10];
int num[maxn  + 10]; 

int main() {
    for(int i = 1;i <= maxn;++ i) {
        for(int j = i;j <= maxn;j += i) {
            num[j] += i;vec[j].push_back(i);
        }
    }
    int t;
    scanf("%d",&t);
    int cas = 0;
    while(t --) {
        cas++;
        int k ;
        scanf("%d",&k); printf("Case %d: ",cas);
        if(num[k] - k != k) {
            if(k != 0)puts("Not perfect.");
            else printf("Not perfect.");
        } else {
            int p = vec[k].size() - 1;
            printf("%d = ",k);
            for(int i = 0;i < p;++ i) {
                if(i != p - 1)printf("%d + ",vec[k][i]);
                else printf("%d",vec[k][i]);
            }
            if(t != 0)puts("");
        }
    }
    return 0;
}  

D题Thinking-Bear magic

发现每次面积变为原来的$\frac{1}{\cos(\frac{\pi}{n})^2} $

代码

#include<bits/stdc++.h>
#define Pi 3.14159265359 

double Sin(int n){
    return sin((2.0*Pi)/n);
}
double Cos(int n){
    return cos((2.0*Pi)/n);
}
double Tan(int n){
    return tan((2.0*Pi)/n);
}
double S(int n, double R) {
    return ((0.25*n*R*R)/(double)tan(Pi/n));
}
double calc(int n){
    return cos(Pi/(1.0*n))*cos(Pi/(1.0*n));
}
int main () {
    int T,n,a,l;
    scanf("%d",&T);
    double s;
    int t;
    while(T --) {
        scanf("%d%d%d",&n,&a,&l);
        double gg = calc(n);
        t = 0; s = S(n,(double)a);
        while(s > l) s = gg * s, ++ t;
        printf("%d\n",t);
    }
    return 0;
}  

J题目 Beautiful Numbers

数位dp

代码

#include<bits/stdc++.h>
using namespace std;
inline int read() {
    int x = 0,f = 1;
    char c = getchar();
    while(c < '0' || c > '9')c = getchar();
    while(c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
const int maxn=3e5+5;
const int INF =0x3f3f3f3f;
#define LL long long
int a[20];
LL dp[13][105][150];
int mod;
LL dfs(int pos,int sum,int res,bool limit) {
    if(pos == -1) return (sum == mod && !res);
    if(dp[pos][sum][res] != -1 && !limit) return dp[pos][sum][res];
    int up = limit ? a[pos] : 9;
    LL res = 0;
    for(int i = 0;i <= up;++ i) {
        if(i + sum > mod) break;
        res += dfs(pos - 1,sum + i,(res * 10 + i) % mod,limit && i == a[pos]);
    }
    if(!limit) dp[pos][sum][res] = res;
    return res;
}
LL solve(LL n) {
    int pos=0;
    LL x = n;
    while(x) a[pos ++] = x % 10, x /= 10;
    LL res = 0;
    for(int i = 1;i <= 9 * pos;++ i) {
        mod = i;
        memset(dp,-1,sizeof(dp));
        res += dfs(pos-1,0,0,true);
    }
    return res;
}
int main() {
    int T = read();
    int cas = 0;
    while(T --) {
        cas ++;
        LL n = read();
        printf("Case %d: %lld\n",cas,solve(n));
    }
    return 0;
} 

K题 Matrix Multiplication

矩乘裸题

代码

#include<bits/stdc++.h>
using namespace std;
struct MMMM {
    int m[21][21];
    int r,c;
    MMMM() {}
    MMMM(int n) {memset(m, false, sizeof m);r = c = n; for (int i = 0; i < r; i +=1) m[i][i] = 1;}
    MMMM(int R,int C) {memset(m, false, sizeof m);r = R,c = C;}
    MMMM operator * (const MMMM & o)const {
        MMMM res = MMMM(r, o.c);
        for (int i = 0; i< r;i += 1)
            for (int  j = 0 ;j < o.c; j += 1)
                for (int k = 0; k < c; k += 1 )
                    res.m[i][j] += 1ll * m[i][k] * o.m[k][j];
        return res;
    }
    void print() {
        for (int i =0 ;i < r;i += 1) {
            for (int j = 0; j < c; j += 1) {
                if(j!=c-1)printf("%d ",m[i][j]);
                else printf("%d",m[i][j]);
            }
            puts("");
        }
    }
    void input() {
        for (int i = 0; i< r; i += 1)
            for (int j = 0; j < c; j += 1)
                scanf("%d", &m[i][j]);
    }
};
int main () {
    int T;
    scanf("%d",&T);
    for (int i =1; i <= T; i += 1) {
        int r1,c1,r2,c2;
        scanf("%d%d%d%d", &r1,&c1,&r2,&c2);
        MMMM a,b;
        a=MMMM(r1,c1), b= MMMM(r2,c2);
        a.input(); b.input();
        printf("Case %d:\n",i);
        if (c1 != r2) {
            printf("ERROR\n");
            continue;
        }
        MMMM c = a * b;
        c.print();
    }
    return 0;
} 

原文地址:https://www.cnblogs.com/sssy/p/9426643.html

时间: 2024-08-10 20:32:08

2018 ACM 国际大学生程序设计竞赛上海大都会部分题解的相关文章

2018 ACM 国际大学生程序设计竞赛上海大都会赛

传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:00时长: 5小时 比赛情况 实录 难度差不多介于省赛和区域赛之间吧.开题A是计算几何,有点思路后就先放下去写签到题,B读错题WA一发,K直接套模板,然后就接着看A.之前写过类似题,没注意数据范围就头铁地交了发n3的代码,TE后才发现数据范围是之前那道十多倍,就听学长的先看D.推十分钟公式无果后打算直

2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A Fruit Ninja

传送门 题解:给你一堆点问你能不能找出一条直线,使其穿过的点大于n*x. 题解:想起某道CF题目,给你一堆点问你能不能找出两条直线使其穿过所有的点.当时就是在一定时限内随机找了两个点,再枚举每个点是否满足,如果超过该时限仍然不满足则直接返回no.这题也是一样的做法,直接随机两个点,再枚举过去.因为x为0.1到0.9,所以如果所给数据满足条件,那么它有极大概率能够跑出结果.4发只有一次超时 #include<bits/stdc++.h> //CLOCKS_PER_SEC #define se s

2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)

题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a matrix from two matrices with entries in a field, or, more generally, in a ring or even a semiring. The matrix product is designed for representing the

2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)

题目描述 We consider a positive integer perfect, if and only if it is equal to the sum of its positive divisors less than itself. For example, 6 is perfect because 6 = 1 + 2 + 3. Could you write a program to determine if a given number is perfect or not?

2018 ACM 国际大学生程序设计竞赛上海大都会 F - Color it (扫描线)

题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点.求最后剩余白色点数. 分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白色点数即列数-区间覆盖的总长度.这就转化成了扫描线的问题. #include<bits/stdc++.h> using namespace std; typedef long long LL; const int maxn =1e4+5; struct Circle{ LL x,y,r; }p[m

第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安站

 第39届ACM国际大学生程序设计竞赛 亚洲区域赛(现场赛)西安赛区总结报告 报告人:田思明 队名:ACpioneer 队长:陈志阳,队员:顾振兴,田思明 西安区域赛告下帷幕,我和陈志阳,顾振兴组成的ACpioneer队最终获得了一块宝贵的铜牌.首先要感谢陈志阳和顾振兴两位杰出队友的努力训练和出色表现,我作为一个新人跟着他们学到了很多很多,也十分珍惜和他们在一起的训练,比赛时光,其次要感谢陈志老师,不辞辛劳陪我们5队和6队前往西安参加比赛,还要感谢集训队所有曾经帮过我们的所有队员们,记得cdy

《ACM国际大学生程序设计竞赛题解Ⅰ》——基础编程题

这个专栏开始介绍一些<ACM国际大学生程序设计竞赛题解>上的竞赛题目,读者可以配合zju的在线测评系统提交代码(今天zoj貌似崩了). 其实看书名也能看出来这本书的思路,就是一本题解书,简单暴力的通过题目的堆叠来提升解决编程问题的能力. 那么下面开始探索吧. zoj1037: BackgroundFor years, computer scientists have been trying to find efficient solutions to different computing p

第39届ACM国际大学生程序设计竞赛大陆地区赛站奖励方案

搬砖: 为了更好地吸引优秀选手参加第39届ACM国际大学生程序设计竞赛,全球赞助商的经费用于参赛队服和赛事的承办活动,中国赛区赞助商提供的经费用于优秀参赛队的奖励(包括奖金.奖牌.奖杯.获奖证书及奖品等), 竞赛命题,参赛手册,竞赛宣传方面的费用支出.每个赛区的具体奖励方式如下: 设冠军.亚军.季军三座奖杯,分别颁发奖金5000.3500.2000元人民币: 设15名金奖(包括冠.亚.季军)和30名银奖, 铜奖数量为参赛队数的30%: 获金奖的队(未获奖杯的队)每队颁发奖金1000元人民币; 获

《ACM国际大学生程序设计竞赛题解I》——6.10

Pku 1143: Description Christine and Matt are playing an exciting game they just invented: the Number Game. The rules of this game are as follows. The players take turns choosing integers greater than 1. First, Christine chooses a number, then Matt ch