UVa 10880 - Colin and Ryan
来源:互联网 发布:淘宝投诉不成立怎么办 编辑:程序博客网 时间:2024/05/29 19:12
有n块饼干,请G个客人,每个客人吃Q块饼干,要求最后剩m块。
思路:只要求出n-m这个数的因子就好,每个因子代表可以请几个客人,但是要满足要求,Q>m,最后要求出去Q,从小到大的顺序
/************************************************************************* > File Name: 10880.cpp > Author: Toy > Mail: ycsgldy@163.com > Created Time: 2013年06月07日 星期五 16时00分58秒 ************************************************************************/#include <algorithm>#include <iostream>#include <iomanip>#include <cstring>#include <cstdlib>#include <climits>#include <sstream>#include <fstream>#include <cstdio>#include <string>#include <vector>#include <queue>#include <cmath>#include <stack>#include <map>#include <set>using namespace std;const int INF = 0x7fffffff;typedef pair<int,int> II;typedef vector<int> IV;typedef vector<II> IIV;typedef vector<bool> BV;typedef long long i64;typedef unsigned long long u64;typedef unsigned int u32;#define For(t,v,c) for(t::const_iterator v=c.begin(); v!=c.end(); ++v)#define IsComp(n) (_c[n>>6]&(1<<((n>>1)&31)))#define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))const int MAXP = 46341; //sqrt(2^31)const int SQRP = 216; //sqrt(MAX)int _c[(MAXP>>6)+1];IV primes, opt, vec;int Case, n, m;void prime_sieve (){ for ( int i = 3; i <= SQRP; i += 2 ) if ( !IsComp ( i ) ) for ( int j = i * i; j <= MAXP; j += i + i ) SetComp ( j ); primes.push_back( 2 ); for ( int i = 3; i <= MAXP; i += 2 ) if ( !IsComp ( i ) ) primes.push_back( i );}void divisors ( int n, IV &ds ) { ds.clear ( ); ds.push_back ( 1 ); int sn = sqrt ( n ); For ( IV, it, primes ) { int p = *it; if ( p > sn ) break; if ( n % p != 0 ) continue; IV aux ( ds.begin (), ds.end() ); int q = 1; while ( n % p == 0 ) { q *= p; n /= p; For ( IV, v, ds ) aux.push_back( ( *v * q ) ); } sn = sqrt ( n ); ds = aux; } if ( n > 1 ) { IV aux ( ds.begin(), ds.end() ); For ( IV, v, ds ) aux.push_back( *v * n ); ds = aux; }}int main ( ) { prime_sieve (); scanf ( "%d", &Case ); for ( int cnt = 1; cnt <= Case; ++cnt ) { scanf ( "%d%d", &n, &m ); printf ( "Case #%d:", cnt ); if ( m == n ) printf ( " 0" ); else { vec.clear(); int R = n - m; divisors( R, opt ); For ( IV, it, opt ) { if ( ( R / *it ) > m ) vec.push_back ( R / *it ); } sort ( vec.begin (), vec.end () ); For ( IV, it, vec ) printf ( " %d", *it ); } printf ( "\n" ); } return 0;}
- UVa 10880 - Colin and Ryan
- The Secret Garden——7、Colin and the garden
- Ryan Penn
- colin在MINI2440构建系统
- Uva 11292 and Uva 11729
- Ryan 的留言簿
- RYAN First Blog
- uva 12898 And Or
- UVA 12898 AND OR
- Choose and divide UVA
- Cows and Cars UVA
- Doves and bombs UVA
- Choose and divide UVA
- Cows and Cars UVA
- Erasing and Winning UVA
- Choose and divide UVA
- Prince and Princess UVA
- Choose and divide UVA
- C# Winform应用程序占用内存较大解决方法整理
- android 如何控制Gallery 滑动速度
- 转:python模块学习 ---- smtplib 邮件发送
- 字段类型设计与实际业务不符引发的问题1
- ADB server didn't ACK * failed to start daemon * 解决方案
- UVa 10880 - Colin and Ryan
- AVR 工具指南(一)
- 为什么用栈,参数、局部变量入栈我怎么去访问的?
- JAVA类装载器classloader和命名空间namespace
- 第十次上机实验
- android 下的适配器
- 光标定位并选中
- ##计划任务## 把python文件打包成exe
- 如何判断大端小端