B Equal Rectangles

题意:

给你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 }

C. Common Divisors

题意:

给你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的更多相关文章

  1. Codeforces Round #579 (Div. 3)

    Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include &l ...

  2. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  3. Codeforces Round #579 (Div. 3) 套题 题解

    A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针 ...

  4. CF #579 (Div. 3) B.Equal Rectangles

    B.Equal Rectangles time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

  5. 【cf比赛练习记录】Codeforces Round #579 (Div. 3)

    思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, ...

  6. Codeforces Round #579 (Div. 3) 题解

    比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否 ...

  7. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

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

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

随机推荐

  1. 肌肤管家SkinRun V3S智能皮肤检测仪,用AI探索肌肤问题

    继肌肤管家SkinRun V3皮肤检测仪之后,肌肤管家SkinRun近期又一重磅推出的肌肤管家SkinRun V3S 智能肌肤测试仪引起了美业人的广泛关注.据了解它汇集百万皮肤数据,利用五光谱原理和人 ...

  2. MongoDB备份(mongodump)与恢复(mongorestore)工具实践

    mongodump和mongorestore实践 1.mongodump备份工具 mongodump能够在Mongodb运行时进行备份,它的工作原理是对运行的Mongodb做查询,然后将所有查到的文档 ...

  3. Memcached repcached 高可用

    Memcached + repcached 高可用环境 repcached 就是一个让memcached的机器能够互为主从,前端可以加一台HAProxy,后端两台memcached互为主从后,写入任何 ...

  4. 微信小程序request请求的封装

    目录 1,前言 2,实现思路 3,实现过程 3.1,request的封装 3.2,api的封装 4,实际使用 1,前言 在开发微信小程序的过程中,避免不了和服务端请求数据,微信小程序给我们提供了wx. ...

  5. docker 报错: Cannot connect to the Docker daemon at unix:///var/run/docker.sock.

    最近在 Windows 子系统 WSL 上面安装了一个 ubuntu18.04, 安装完docker 跑 hello-world 的时候报错了 docker: Cannot connect to th ...

  6. 【Jboss】一台服务器上如何部署多个jboss

    一台服务器上如何部署多个jboss呢?直接把整个部署环境copy一份到相应的目录下? 这样只是前提,但是启动复制后的jboss就会发现,有很多端口被占用 3873,8080,8009,8443,808 ...

  7. paramiko模块简单用法

    最简单最基本的用法 1 #__*__coding:utf-8__*__ 2 import paramiko 3 hostname = '192.168.1.1' 4 username = 'root' ...

  8. JAVA之路_假克隆、浅克隆、深克隆

    一.JAVA假克隆 Java中,对于基本类型,可以用"="进行克隆,而对于引用类型却不能简单的使用"="进行克隆,这与JAVA的内存使用空间有关,JAVA在栈中 ...

  9. [Usaco2005 Mar]Out of Hay 干草危机

    题目描述 Bessie 计划调查N (2 <= N <= 2,000)个农场的干草情况,它从1号农场出发.农场之间总共有M (1 <= M <= 10,000)条双向道路,所有 ...

  10. kaggle新手如何在平台学习大神的代码

    原创:数据臭皮匠  [导读]Kaggle ,作为听说它很牛X但从未接触过的同学,可能仅仅了解这是一个参加数据挖掘比赛的网站,殊不知Kaggle也会有赛题相关的数据集, 比如我们熟知的房价预测.泰坦尼克 ...