UVa 10407 - Simple division

题目:给你几个数,求使他们同于的最大除数。

分析:数论。取其中两不相同数的差,差值一定是除数的倍数,利用差值枚举除数即可。

说明:小心都是素数的情况,被坑了╮(╯▽╰)╭。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>

using namespace std;

long long save[1001];

int main()
{
	int count;
	while (cin >> save[count=0] && save[count]) {
		count ++;
		while (cin >> save[count] && save[count])
			count ++;

		sort(save, save+count);
		int s = save[count-1]-save[0];
		for (int i = 1 ; i < count ; ++ i)
			if (save[i] > save[i-1] && save[i]-save[i-1] < s)
				s = save[i]-save[i-1];

		for (int i = 1 ; i <= s ; ++ i)
			if (s%i == 0) {
				int d = s/i,r = (save[0]%d+d)%d,flag = 1;
				for (int j = 1 ; j < count ; ++ j)
					if ((save[j]%d+d)%d != r) {
						flag = 0;
						break;
					}
				if (flag) {
					cout << d << endl;
					break;
				}
			}
	}
	return 0;
}
时间: 2024-10-20 02:41:39

UVa 10407 - Simple division的相关文章

uva 12253 - Simple Encryption(dfs)

题目链接:uva 12253 - Simple Encryption 题目大意:给定K1,求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用快速幂取模判断结果. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const ll ite=(1<<20)-1; ll N; /* l

uva 10014 Simple calculations

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=955 根据递推公式推倒出a1的公式. a1=(n*a0+an+1-2*(n*c1+(n-1)*c2+...+cn))/(n+1); 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm>

Uva 10912 Simple Minded Hashing (计数DP)

4th IIUC Inter-University Programming Contest, 2005 H Simple Minded Hashing Input: standard input Output: standard output Problemsetter: Sohel Hafiz All of you know a bit or two about hashing. It involves mapping an element into a numerical value usi

UVA 10407 差分思想的运用

就是每两项相减,肯定能被模数整除. 1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <algorithm> 5 using namespace std; 6 7 const int Maxn=1010; 8 int f[Maxn],n,Ans; 9 int Gcd(int a,int b) {if (b==0) return a; return Gcd(b,a

UVA 10994 Simple Addition

感觉这个一定要记下来涨教训啊.一开始找规律找错了.判断超麻烦还各种WA.浪费N个小时啊..人家几行就A了.太弱, #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype

UVA 10912 Simple Minded Hashing

题意就略了.刚一看被数据吓住了.看到字符要求严格递增.那么如果字串长大于26那必然方案数目为0:同时1+2+3....+24+25+26=351如果大于这个数也是不可能的 令dp[i][j][k]表示第i位为第j个字符和为K时的方案数目 那么 dp[i][j][k]=sum(dp[i-1][m][k-t])  {m<j;k-t尝试将第j位置为t} #include <map> #include <set> #include <list> #include <

UVa 11859 (Nim) Division Game

把每一行m个数所有的素因子看做一堆,就把问题转化为n堆的Nim游戏. 然后预处理一下10000以内每个数素因数的个数,再根据书上的Bouton定理,计算一下n行素因数个数的异或和. 为0是先手必败局面,输出NO,否则输出YES 1 #include <cstdio> 2 #include <cmath> 3 4 const int maxp = 10000; 5 int f[maxp + 10]; 6 7 int main() 8 { 9 //freopen("in.tx

how to generate an analog output from a in-built pwm of Atmega 32AVR microcontrloller?

how to generate an analog output from a in-built pwm of Atmega 32AVR microcontrloller? you need a resistor, a capacitor and an opamp. opamp is not really necessary when you are driving a mosfet, but will make life a bit easier. just be aware, that th

IE低版本 canvas的支持

// Copyright 2006 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licens