UVA 11827 Maximum GCD (输入流)
题目:传送门
题意:求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 (输入流)的更多相关文章
- UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...
- UVA 11827 Maximum GCD
F - Maximum GCD Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Given the ...
- UVA 11827 Maximum GCD【GCD,stringstream】
这题没什么好说的,但是输入较特别,为此还WA了一次... 题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge& ...
- 邝斌带你飞之数论专题--Maximum GCD UVA - 11827
Given the N integers, you have to find the maximum GCD (greatest common divisor) of every possible p ...
- Maximum GCD(UVA 11827)
Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...
- UVA11827 Maximum GCD
/* UVA11827 Maximum GCD https://vjudge.net/contest/153365#problem/V 数论 gcd 水题,然而读入比较坑 * */ #include ...
- uva 10951 - Polynomial GCD(欧几里得)
题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...
- UVa 10827 - Maximum sum on a torus
题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...
- Maximum GCD(fgets读入)
Maximum GCD https://vjudge.net/contest/288520#problem/V Given the N integers, you have to find the m ...
随机推荐
- 萤火虫算法-python实现
FAIndividual.py import numpy as np import ObjFunction class FAIndividual: ''' individual of firefly ...
- POJ2286 The Rotation Game
Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see ...
- ubuntu安装spark on yarn
安装spark 安装hadoop 安装ssh,调试免密钥登录 配置hadoop 配置yarn 测试
- 浅谈datagrid详细操作单元格样式
http://www.easyui.info/archives/470.html 今天有朋友问到:“如果设置列标题居中而列内容居右显示?”,仔细查了一下api,目前版本提供了两个相关的列属性,alig ...
- xampp 安装red扩展出错解决
Linux Mint + Xampp Error + ‘grep: /opt/lampp/include/php/main/php.h: No Such File Or Directory’ FEBR ...
- Eigenvectors and eigenvalues
http://setosa.io/ev/eigenvectors-and-eigenvalues/ Explained Visually Tweet By Victor Powell and Lew ...
- Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/dyld_sim is not owned by root.
sudo chown -R root /Applications/Xcode6.1.1.app/ 这里把这个 /Applications/Xcode6.1.1.app/替换成你xocde据在的位置
- Cannot attach the file as database 'membership'.
Cannot attach the file 'D:\GitHome\cae\CAE\App_Data\membership.mdf' as database 'membership'. 说明: 执行 ...
- LUA的编译、环境等
Lua的环境.编译等 Lua命令行 lua命令行选项: -i:进入交互式 -e:执行lua代码 -l:加载库文件 例如使用下面的命令启动lua解释器,可以重新定义lua提示符. lua -i -e & ...
- 使用key链接远程Git仓库
使用密钥来访问Git仓库比密码安全多了,只要把公钥配置在远程端,把密钥放到~/.ssh/里以id_rsa命名即可. 不过有人要问如果有多个仓库,而且用了不同密钥怎么办? 这时候可以在~/.ssh/文件 ...