题目:传送门

题意:求n个数的最大公约数,暴力不会超时,难点在没有个数控制的输入。

题解:用特殊方法输入。

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int gcd(int a,int b)
{
if(b==) return a;
return gcd(b,a%b);
}
int main()
{
int t;
cin>>t;
getchar();
while(t--)
{
char c;
int data[],cnt=;
while((c=getchar())!='\n')
{
if(c>=''&&c<='')
{
ungetc(c,stdin);//将字符c退回到输入流中
scanf("%d",&data[cnt++]);
}
}
int ans=;
for(int i=; i<cnt; i++)
{
for(int j=i+; j<cnt; j++)
{
ans=max(ans,gcd(data[i],data[j]));
}
}
cout<<ans<<endl;
}
return ;
}

UVA 11827 Maximum GCD (输入流)的更多相关文章

  1. UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)

    两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...

  2. UVA 11827 Maximum GCD

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

  3. UVA 11827 Maximum GCD【GCD,stringstream】

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

  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. BZOJ-2242 计算器 快速幂+拓展欧几里得+BSGS(数论三合一)

    污污污污 2242: [SDOI2011]计算器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2312 Solved: 917 [Submit][S ...

  2. SpringMVC配置数据库连接池

    http://www.cnblogs.com/coqn/archive/2012/08/15/SpringMvc%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E9%85%8 ...

  3. HD 2177(威佐夫博弈 入门)

    取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  4. Spring学习3—控制反转(IOC)基于Annotation(注解)的依赖注入实现

    一.依赖注入--手工装配—注解方式 在java代码中使用@Autowired或@Resource注解方式进行装配的前提条件是:   1.引入context命名空间 需要在xml配置文件中配置以下信息: ...

  5. [Angularjs]视图和路由(三)

    写在前面 上篇文章主要介绍了路由中when方法的第二个参数,常见的几个属性,以及作用.本篇文章,将介绍和路由相关的几个常见的服务. 系列文章 [Angularjs]ng-select和ng-optio ...

  6. html标签页图标

    在head标签加入如下内容: <!--可以在收藏夹中显示出图标--> <link rel="Bookmark" type="image/png" ...

  7. 工具类HttpServerUtility

    在ASP.NET服务器上提供一个辅助的工具类HttpServerUtility,该类提供了一些处理请求的辅助方法. MapPath:计算网站中虚拟路径所对应的物理文件路径. HtmlEncode:将H ...

  8. Windows下文件的所有和权限

    跟linux不同, 在linux下 ,文件的所有者,就拥有对文件的所有读写执行的权限, 而windows, 文件的所有者不一定对文件拥有所有的权限, 场景: 要对系统文件(windows\system ...

  9. linux的cgroup控制

    cgroup:control group-控制群组:将用户(的进程)加入某个群组(又叫控制器controller), 通过 指定群组对资源-cpu 内存 network等的使用,来限制用户对计算机资源 ...

  10. tyvj4221 货车漂移

    背景 蒟蒻中学的蒟蒻遇到了一些小问题. 描述 蒟蒻考完noip也就要回家种田了,他老家的田地在s点,可是种子市场在e点,为了购买种子,中途要经过很多城市,这导致快递费非常的贵(因为快到双11了),于是 ...