题目链接

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 国际大学生程序设计竞赛上海大都会部分题解的更多相关文章

  1. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it

    链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...

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

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...

  3. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)

    2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...

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

    传送门:2018 ACM 国际大学生程序设计竞赛上海大都会赛 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛2018-08-05 12:00:00 至 2018-08-05 17:00:0 ...

  5. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)

    题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...

  6. 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D

    A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...

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

    题意:一个N*M的矩形,每个点初始都是白色的,有Q次操作,每次操作将以(x,y)为圆心,r为半径的区域涂成黑点.求最后剩余白色点数. 分析:对每行,将Q次操作在该行的涂色视作一段区间,那么该行最后的白 ...

  8. 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 ...

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

    题目描述 In mathematics, matrix multiplication or matrix product is a binary operation that produces a m ...

随机推荐

  1. 小贾漫谈——Java反射

    一.Class的API 二.测试使用的JavaBean class Admin{ //字段 public String userName; public String pwd; private int ...

  2. 第六节 事务XML方式[声明方式]

    事务管理: 管理事务,管理数据,数据完整性和一致性 事务[业务逻辑] : 由一系列的动作[查询书价格,更新库存,更新余额],组成一个单元[买书业务], 当我们动作当中有一个错了,全错~ ACID 原子 ...

  3. bzoj千题计划202:bzoj3191: [JLOI2013]卡牌游戏

    http://www.lydsy.com/JudgeOnline/problem.php?id=3191 每个人获胜的概率只与其在排列中与庄家的相对位置有关 dp[i][j] 还剩i个人时,从庄家数第 ...

  4. Sublime Text 3 绿色汉化版 x64

    之前做了<Sublime Text 2 绿色汉化版 x64>,这些天抽空做了下 ST3 的汉化.. 果然我没有任何理由爱上 ST3,不仅pojie麻烦,而且汉化更麻烦,菜单字符长度做了限制 ...

  5. [原]JUnit 自定义扩展思路

    1. 理解Annotation,http://www.cnblogs.com/mandroid/archive/2011/07/18/2109829.html 2. JUNIT整体执行过程分析,htt ...

  6. javascript私有方法揭示为公有方法

    揭示模式可用于将私有方法暴露为公共方法.当为了对象的运转而将所有功能放置在一个对象中以及想尽可能地保护该对象,这种揭示模式就非常有用. 板栗: var myarray; (function(){ va ...

  7. 最小生成树问题------------Prim算法(TjuOj_1924_Jungle Roads)

    遇到一道题,简单说就是找一个图的最小生成树,大概有两种常用的算法:Prim算法和Kruskal算法.这里先介绍Prim.随后贴出1924的算法实现代码. Prim算法 1.概览 普里姆算法(Prim算 ...

  8. VBScript操作SFTP

    示例代码主要通过VBScript实现对SFTP的上传下载功能 ' Return yyyyMM base on current date Function FormatCurrentDate() Cur ...

  9. 『Matplotlib』数据可视化专项

    一.相关知识 官网介绍 matplotlib API 相关博客 matplotlib绘图基础 漂亮插图demo 使用seaborn绘制漂亮的热度图 fig, ax = plt.subplots(2,2 ...

  10. CRT/LCD/VGA Information and Timing【转】

    转自:http://www.cnblogs.com/shangdawei/p/4760933.html 彩色阴极射线管的剖面图: 1. 电子QIANG Three Electron guns (for ...