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;
}
2018 ACM 国际大学生程序设计竞赛上海大都会部分题解的更多相关文章
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛
传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)
题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D
A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会 F - Color it (扫描线)
题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点.求最后剩余白色点数. 分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-B-Perfect Numbers(完数)
题目描述 We consider a positive integer perfect, if and only if it is equal to the sum of its positive d ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛-K-Matrix Multiplication(矩阵乘法)
题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...
随机推荐
- Python常用模块-随机数模块(random)
Python常用模块-随机数模块(random) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.常用方法举例 #!/usr/bin/env python #_*_coding: ...
- 函数和常用模块【day06】:shutil模块(四)
本节内容 简书 模块详解 压缩解压 一.简述 我们在日常处理文件时,经常用到os模块,但是有的时候你会发现,像拷贝.删除.打包.压缩等文件操作,在os模块中没有对应的函数去操作,下面我们就来讲讲高级的 ...
- Kafka 0.8 Consumer设计解析
摘要 本文主要介绍了Kafka High Level Consumer,Consumer Group,Consumer Rebalance,Low Level Consumer实现的语义,以及适用场景 ...
- Does Deep Learning Come from the Devil?
Does Deep Learning Come from the Devil? Deep learning has revolutionized computer vision and natural ...
- 高并发数据库之MySql性能优化实战总结
向MySQL发送一个请求时MySQL具体的操作过程 慢查询 1.慢查询 SHOW VARIABLES LIKE '%quer%' 索引优化技巧 1.对于创建的多列索引(复合)索引,只要查询条件使用了最 ...
- 在html5 canvas的destination-atop属性的一些奇怪的问题
最近在整理canvas的时候发现HTML5 Canvas开发详解一个奇怪的属性解释 目标图形是显示在画布上的位图 而原图形是指要回执在画布上的形状 w3school上面是这样说的 destinatio ...
- 10个造型奇特的css3进度条(有的html被编辑器转义了,上面的代码还是OK的)。。。转载
<div id="caseVerte"> <div id="case1"></div> <div id="c ...
- !DOCTYPE 声明
!DOCTYPE 声明的作用: <!DOCTYPE html> 当使用 position 属性进行对齐时,请始终包含 !DOCTYPE 声明!如果省略,则会在 IE 浏览器中产生奇怪的结果 ...
- 洛谷 P1045 【麦森数】快速幂
不用快速幂,压位出奇迹! 本人是个蒟蒻,不太熟悉快速幂,这里给大家介绍一种压位大法. 让我们来分析一下题目,第一位是送分的,有一个专门求位数的函数:n*log10(2)+1. 然后题目中p<=3 ...
- mybatis输入输出映射——(五)
0.#{}与${}区别 #{}实现的是向prepareStatement中的预处理语句中设置参数值,sql语句中#{}表示一个占位符即?. <!-- 根据id查询用户信息 --> < ...