Codeforces Round #579 (Div. 3) B Equal Rectangles、C. Common Divisors
题意:
给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等
题解:
原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个面积只能是给出的4*n个数中的最小值和最大值的乘积,如果这两个长度不凑成一个矩形,那么肯定全部矩形的面积会出现不一致的
代码:
1 //The idea was to use dichotomies to find that area, and then use that area to figure it out, but it's more complicated than that
2 //If you don't use the smallest and largest as the two sides of a rectangle, there will always be an area larger than that
3 #include <stdio.h>
4 #include <algorithm>
5 #include <iostream>
6 #include <string.h>
7 using namespace std;
8 const int maxn = 405;
9 typedef long long ll;
10 int v[maxn],w[maxn];
11 int main()
12 {
13 int t;
14 scanf("%d",&t);
15 while(t--)
16 {
17 int n;
18 scanf("%d",&n);
19 for(int i=1;i<=4*n;++i)
20 {
21 scanf("%d",&v[i]);
22 }
23 sort(v+1,v+1+4*n);
24 int x=v[1]*v[4*n],flag=1;
25 for(int i=2;i<=2*n;++i)
26 {
27 if(v[i]*v[4*n-i+1]!=x)
28 {
29 flag=0;
30 break;
31 }
32 }
33 for(int i=2;i<=4*n;i+=2)
34 {
35 if(v[i]!=v[i-1])
36 {
37 flag=0;
38 break;
39 }
40 }
41 if(flag) printf("YES\n");
42 else printf("NO\n");
43 }
44 return 0;
45 }
题意:
给你n个数,让你找出来这n个数的公因数有多少个
题解:
肯定不能暴力for循环找,一个数的公因数的因数也是这个数的因数,那么我们就可以找出来这n个数的最大公共因数,然后再在这个因数里面找因数
代码:
1 #include <bits/stdc++.h>
2
3 #define ll long long
4
5 #define sc scanf
6
7 #define pr printf
8
9 using namespace std;
10
11 ll gcd(ll a, ll b)
12
13 {
14
15 return b == 0 ? a : gcd(b, a % b);
16
17 }
18
19 int main()
20
21 {
22
23 int n;
24
25 scanf("%d", &n);
26
27 ll t1, t2;
28
29 sc("%lld", &t1);
30
31 for (int i = 1; i < n; i++)
32
33 {
34
35 sc("%lld", &t2);
36
37 t1 = gcd(t1, t2);
38
39 }
40
41 ll qq = sqrt(t1);
42
43 ll ans = 0;
44
45 for (ll i = 1; i <= qq; i++)
46
47 {
48
49 if (t1 % i == 0)
50
51 {
52
53 ans++;
54
55 if (t1 / i != i)
56
57 ans++;
58
59 }
60
61 }
62
63 printf("%lld", ans);
64
65 }
Codeforces Round #579 (Div. 3) B Equal Rectangles、C. Common Divisors的更多相关文章
- Codeforces Round #579 (Div. 3)
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...
- Codeforces Round #433 (Div. 2)【A、B、C、D题】
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...
- Codeforces Round #579 (Div. 3) 套题 题解
A. Circle of Students 题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...
- CF #579 (Div. 3) B.Equal Rectangles
B.Equal Rectangles time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...
- 【cf比赛练习记录】Codeforces Round #579 (Div. 3)
思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...
- Codeforces Round #579 (Div. 3) 题解
比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否 ...
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #486 (Div. 3)-C. Equal Sums
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #219 (Div. 2) D. Counting Rectangles is Fun 四维前缀和
D. Counting Rectangles is Fun time limit per test 4 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- linux常用命令--转载
转载自: https://www.cnblogs.com/Qsunshine/p/10402179.html 常用指令 ls 显示文件或目录 -l列出文件详细信息l(list) -a列出当前目录下所有 ...
- FAT32、NTFS、exFAT有什么区别?
文件系统 我们经常会对电脑硬盘.U盘.移动硬盘进行格式化,而在格式化硬盘的时候会弹出文件系统的选项,分别有FAT32.NTFS.exFAT三种格式,那么FAT32.NTFS.exFAT有什么区别? 在 ...
- mysql中的基本注入函数
1. 常见数据库注入函数: MYSQL: and length((user))>10 ACCESS: and (select count() from MSysAccessObject)> ...
- Neo4j 图数据库查询
Cypher 介绍 Cypher 介绍:作为Neo4j的查询语言,"Cypher"是一个描述性的图形查询语言,允许不必编写图形结构的遍历代码对图形存储有表现力和效率的查询.Cyph ...
- 记一道C语言编程题(C语言学习笔记)
题目如下 解答如下 #include <stdio.h> #include<math.h> double Mysqrt(double n) { return sqrt(n); ...
- CF625E Frog Fights
有\(n\)只青蛙在一个长度为\(m\)的环上打架:每只青蛙有一个初始位置\(p_i\),和一个跳跃数值\(a_i\).从\(1\)号青蛙开始按序号循环行动,每次若第\(i\)只青蛙行动,则它会向前跳 ...
- atlas读写分离
Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上,修改了大量bug ...
- 六个你不知道的PR快捷键,拯救你的剪辑效率
5G时代到来,会剪辑视频的人,无论在校园还是未来步入职场都很吃香.对于普通人来说,视频处理也成为了一个通用技能.PR是我们大多数人剪辑中,经常会用到的剪辑工具,之前的文章中已经给大家总结了pr的一些提 ...
- A1Z26 Cipher - Letter Number A=1 B=2 C=3 - Online Decoder, Translator https://www.dcode.fr/letter-number-cipher
A1Z26 Cipher - Letter Number A=1 B=2 C=3 - Online Decoder, Translator https://www.dcode.fr/letter-nu ...
- Spring,Spring MVC,MyBatis,Hibernate总结
将之前学习的框架知识进行了UML图总结,若有错误或不当之处,劳烦朋友们指正,会及时作出修改和补充: [toc] Spring Spring MVC MyBatis,Hibernate