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 ...
 
随机推荐
- LeetCode278 第一个错误的版本
			
你是产品经理,目前正在带领一个团队开发新的产品.不幸的是,你的产品的最新版本没有通过质量检测.由于每个版本都是基于之前的版本开发的,所以错误的版本之后的所有版本都是错的. 假设你有 n 个版本 [1, ...
 - 天梯赛练习 L3-007 天梯地图 (30分) Dijkstra
			
题目分析: 本题的题意比较清晰,就是有一个起点和一个终点,给出m条路径,可能是单向的可能是双向的,同时一条路有两个权重,分别是通过这条路需要的时间和这条路的路径长度,题目需要求出两条路径,一条是在最快 ...
 - 【Jboss】一台服务器上如何部署多个jboss
			
一台服务器上如何部署多个jboss呢?直接把整个部署环境copy一份到相应的目录下? 这样只是前提,但是启动复制后的jboss就会发现,有很多端口被占用 3873,8080,8009,8443,808 ...
 - 利用Numpy求解投资内部收益率IRR
			
一. 内部收益率和净现值 内部收益率(Internal Rate of Return, IRR)其实要和净现值(Net Present Value, NPV)结合起来讲.净现值指的是某个投资项目给公司 ...
 - 大数据系列1:一文初识Hdfs
			
最近有位同事经常问一些Hadoop的东西,特别是Hdfs的一些细节,有些记得不清楚,所以趁机整理一波. 会按下面的大纲进行整理: 简单介绍Hdfs 简单介绍Hdfs读写流程 介绍Hdfs HA实现方式 ...
 - mysql 设置外键约束时如何删除数据
			
Mysql中如果表和表之间建立的外键约束,则无法删除表及修改表结构 解决方法是在Mysql中取消外键约束: SET FOREIGN_KEY_CHECKS=0; 然后将原来表的数据导出到sql语句,重新 ...
 - MVC和MTV框架模式
			
1. MVC: MVC,全名是Model View Controller,是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Controller ...
 - Py-re正则模块,log模块,config模块,哈希加密
			
9.re正则表达式模块,用于字符串的模糊匹配 元字符: 第一:点为通配符 用.表示匹配除了换行符以外的所有字符 import re res=re.findall('a..x','adsxwassxdd ...
 - 解析MySQL中存储时间日期类型的选择问题
			
解析MySQL中存储时间日期类型的选择问题_Mysql_脚本之家 https://www.jb51.net/article/125715.htm 一般应用中,我们用timestamp,datetime ...
 - Linux 技巧:让进程在后台运行更可靠的几种方法
			
Linux 技巧:让进程在后台运行更可靠的几种方法 https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html 我们经常会碰到这 ...