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 ...
随机推荐
- LeetCode707 设计链表
设计链表的实现.您可以选择使用单链表或双链表.单链表中的节点应该具有两个属性:val 和 next.val 是当前节点的值,next 是指向下一个节点的指针/引用.如果要使用双向链表,则还需要一个属性 ...
- spring ioc踏出第一步
spring IOC(容器) AOP(面向切面编程) IOC容器:他的功能就是可以整合像 Structs2 .Hibernate.Mybatis: IOC:控制反转:所谓的控制就是控制资源的获取方法, ...
- MySQL全面瓦解18:自定义函数
定义 我们之前学习了MySQL的内置函数,非常丰富,满足了我们对数据操作的大部分需求. 但是如果有一些复杂的业务逻辑在数据库层面就可以完成,无需在程序层面完成的时候,这时候就可以写成MySQL自定义函 ...
- JAVA之路_假克隆、浅克隆、深克隆
一.JAVA假克隆 Java中,对于基本类型,可以用"="进行克隆,而对于引用类型却不能简单的使用"="进行克隆,这与JAVA的内存使用空间有关,JAVA在栈中 ...
- linux opt, usr文件夹说明
linux下各文件夹介绍: https://www.pathname.com/fhs/pub/fhs-2.3.html /usr:系统级的目录,可以理解为C:/Windows/,/usr/lib理解为 ...
- 阿里云OSS对象存储服务(二)
一.使用SDK 在OSS的概览页右下角找到"Bucket管理",点击"OSS学习路径" 点击"Java SDK"进入SDK开发文档 二.创建 ...
- 不用git 手动对比文件差异
使用python脚本比较两个文件的差异内容并输出到html文档中,可以通过浏览器打开查看. 一.脚本使用 对比文件的差异 python python_diff_file.py -f1 web26.co ...
- CentOS对接GlusterFS
存储节点部署示例环境,仅供参考 主机名 IP 系统 gfs01 10.10.10.13 CentOS 7.4.1708 gfs02 10.10.10.14 CentOS 7.4.1708 一.Glus ...
- 聊一聊:Service层你觉得有用吗?
前段日子在社群(点击加入)里看到有人讨论关于Service层接口的问题,DD也经常碰到周围的新人有问过一些类似的问题:一定要写个Service层的接口吗?Service层的接口到底用做什么用的呢?好像 ...
- 前端中的script标签
script标签中的重要属性! . 浏览器解析行内脚本的方式决定了它在看到字符串时,会将其当成结束的 标签.想避免这个问题,只需要转义字符"\" ①即可: 要包含外部文件中的 Ja ...