两个暴力题。。

题目传送:11827 Maximum GCD

AC代码:

#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std; int a[105]; int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
} int main() {
int T;
scanf("%d", &T);
getchar();
while(T --) {
int cnt = 0;
char s[100005];
gets(s);
int len = strlen(s);
for(int i = 0; i < len; i ++) {
if(s[i] != ' ') {
int tmp = 0;
for(; isdigit(s[i]); i ++) {
tmp = tmp * 10 + s[i] - '0';
}
a[cnt ++] = tmp;
}
} int ans = 0;
for(int i = 0; i < cnt; i ++) {
for(int j = i + 1; j < cnt; j ++) {
ans = max(ans, gcd(a[i], a[j]));
}
} printf("%d\n", ans);
}
return 0;
}

题目传送:10200 Prime Time


AC代码:

#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define INF 0x7fffffff
using namespace std; int biao[10005]; bool isPrime(int x) {
if(x == 2 || x == 3) return true;
int m = (int)sqrt(x + 0.5);
for(int i = 2; i <= m; i ++) {
if(x % i == 0) return false;
}
return true;
} void init() {
for(int i = 0; i < 40; i ++) {
biao[i] = 1;
}
for(int i = 40; i < 10005; i ++) {
int t = i * i + i + 41;
if(isPrime(t)) {
biao[i] = 1;
}
else biao[i] = 0;
}
} int main() {
init();
int a, b;
while(scanf("%d %d", &a, &b) != EOF) {
int cnt = 0;
for(int i = a; i <= b; i ++) {
cnt += biao[i];
}
printf("%.2lf\n", (cnt * 1.0) / (b - a + 1) * 100.0 + 1e-6);//注意浮点数误差
}
return 0;
}

UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)的更多相关文章

  1. UVA 11827 Maximum GCD

    F - Maximum GCD Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Given the ...

  2. UVA 11827 Maximum GCD【GCD,stringstream】

    这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...

  3. UVA 11827 Maximum GCD (输入流)

    题目:传送门 题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入. 题解:用特殊方法输入. #include <iostream> #include <cmath&g ...

  4. 邝斌带你飞之数论专题--Maximum GCD UVA - 11827

    Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible p ...

  5. Maximum GCD(UVA 11827)

    Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...

  6. UVA11827 Maximum GCD

    /* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...

  7. uva 10951 - Polynomial GCD(欧几里得)

    题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...

  8. UVa 10827 - Maximum sum on a torus

    题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...

  9. Maximum GCD(fgets读入)

    Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...

随机推荐

  1. Keepalived中Master和Backup角色选举策略

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://ixdba.blog.51cto.com/2895551/1544858 在Kee ...

  2. hdu 4301 dp

    Divide Chocolate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. 06深入理解C指针之---指针操作和比较

    该系列文章源于<深入理解C指针>的阅读与理解,由于本人的见识和知识的欠缺可能有误,还望大家批评指教. 指针作为一种特殊类型的变量,必须遵守C语言中变量先声明后使用的原则.本节内容中指针的操 ...

  4. 25深入理解C指针之---传递数组

    一.传递数组:将数组作为参数传入函数,或将数组作为数据当成是函数的返回值 1.定义:可以传入和传出数组 2.特征: 1).将数组作为参数传递给函数的本质是传递数组的地址,这种传递无需复制数组元素,所以 ...

  5. hdu 5459(递推好题)

    Jesus Is Here Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)To ...

  6. LeetCode OJ--Path Sum *

    https://oj.leetcode.com/problems/path-sum/ 树的深搜,求从根到叶子的路径. 记住深搜的样子 #include <iostream> using n ...

  7. Codeforces Gym101502 H.Eyad and Math-换底公式

    H. Eyad and Math   time limit per test 2.0 s memory limit per test 256 MB input standard input outpu ...

  8. Codeforces 804D Expected diameter of a tree(树的直径 + 二分 + map查询)

    题目链接 Expected diameter of a tree 题目意思就是给出一片森林, 若把任意两棵树合并(合并方法为在两个树上各自任选一点然后连一条新的边) 求这棵新的树的树的直径的期望长度. ...

  9. jenkins配置Maven的私有仓库Nexus

    1.什么是nexus? Neux:MAVEN的私有仓库; 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库 ...

  10. JSP页面顶端出现错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的问题解决

    原理:把RunTime容器添加进去,比如tomcat的. 1.项目右键->[Build Path]->[Configure Build Path...] 2.把tomcat的runtime ...