题目链接

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. indeed招聘

    https://cn.indeed.com/%E5%B7%A5%E4%BD%9C-%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD%E5%85%AC%E5%8F%B8-%E5% ...

  2. Solr记录-solr基础内容

    Solr架构(体系结构) 在本章中,我们将讨论Apache Solr的架构. 下图显示了Apache Solr的体系结构的框图. Solr架构 - 构件块以下是Apache Solr的主要构建块(组件 ...

  3. python制作查找单词翻译的脚本

    本人由于英语渣,在linux底下经常看文档,但是有没有想有道词典这种软件,所以遇到不懂的单词只能手动复制粘贴在网上查找,这样就很不方便,学了python之后,就试着自己尝试下个在命令行下查找单词翻译的 ...

  4. javascript的this分别代表什么

    鉴于大家对this到底代表的是什么有疑问,现在将我个人理解的this的情况整理如下.有错误请指正. 第一种情况:  如果是一个全局的function,则this相当于window对象. 这个打印出来的 ...

  5. LeetCode-Valid Number - 有限状态机

    判断合法数字,之前好像在哪里看到过这题, 记得当时还写了好久,反正各种改, 今天看到了大神的解法(https://github.com/fuwutu/LeetCode/blob/master/Vali ...

  6. org.hibernate.TransientObjectException异常

    代码如下: /** * 测试4:新增一个秘书角色,并赋给张三该角色 */ @Test public void test4(){ Session session = HibernateUtils.ope ...

  7. 善用backtrace解决大问题【转】

    转自:https://www.2cto.com/kf/201107/97270.html 一.用途: 主要用于程序异常退出时寻找错误原因 二.功能: 回溯堆栈,简单的说就是可以列出当前函数调用关系 三 ...

  8. VMware下centos桥接模式静态ip配置

    声明:本文转载自http://blog.csdn.net/ltr15036900300/article/details/48828207,非原创. 一.配置虚拟机centos网络 备份网络文件 [ro ...

  9. Project Euler Problem4

    Largest palindrome product Problem 4 A palindromic number reads the same both ways. The largest pali ...

  10. 织梦任意页面调用{dede:field.content/}的方法

    过滤掉所有的html代码,只显示文字,具体的ID自己更改. 代码如下: {dede:sql sql='Select content from dede_arctype where id=1'} [fi ...