题意:
给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等
题解:
原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个面积只能是给出的4*n个数中的最小值和最大值的乘积,如果这两个长度不凑成一个矩形,那么肯定全部矩形的面积会出现不一致的
代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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个数的最大公共因数,然后再在这个因数里面找因数
代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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 }