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 ...
随机推荐
- poj 3463 最短路与次短路&&统计个数
题意:求最短路和比最短路长度多1的次短路的个数 本来想图(有)方(模)便(版)用spfa的,结果妹纸要我看看dijkstra怎么解.... 写了三遍orz Ver1.0:堆优化+邻接表,WA //不能 ...
- linux内核数据结构学习总结
目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...
- eclipse启动tomcat错误:A Java Exception has occurred
在tomcat bin目录下执行startup.bat可以正常启动,但在eclipse下安装了tomcat插件并且配置tomcat路径后启动且报错:A Java Exception has occur ...
- Alpha阶段个人总结
一. 工作总结 第一次接触通信和服务端框架,在前期准备阶段学习了很多不同的技术,也相应花费了很多时间去尝试.刚开始时还不知道框架这种东西,准备自己写,于是学习并尝试了一些简单的HTTP通信,比较麻烦, ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Linux X Window System运行原理和启动过程
本文主要说明X Window System的基本运行原理,其启动过程,及常见的跨网络运行X Window System. 一) 基本运行原理 X Window System采用C/S结构,但和我们常见 ...
- Spring学习8-用MyEclipse搭建SSH框架 Struts Spring Hibernate
1.new一个web project. 2.右键项目,为项目添加Struts支持. 点击Finish.src目录下多了struts.xml配置文件. 3.使用MyEclipse DataBase Ex ...
- mvc 简单笔记
---恢复内容开始--- 入口文件 index.php 唯一的一个让浏览器直接请求的脚本文件 控制器 协调模型和试图 模型 提供数据 保存数据 数据的验证 试图 只负责显示 <?php $c = ...
- Python socket编程之一:
soket 编程步骤 # -*- coding: utf-8 -*- ################################################################# ...
- 去除DedeCms 5.7后台版权广告链接的方法
织梦DedeCms 5.7后台有很多的织梦官方的广告链接,下面我们来将这些广告去掉吧. 一.去处后台登陆页login.php广告链. 1.找到登录界面模板文件/dede/templets/login. ...