NOIopenjudge 407:Heritage
- 总时间限制:
- 5000ms
- 内存限制:
- 65536kB
- 描述
- Your rich uncle died recently, and the heritage needs to be divided among your relatives and the church (your uncle insisted in his will that the church must get something). There are N relatives (N <= 18) that were mentioned in the will. They are sorted in descending order according to their importance (the first one is the most important). Since you are the computer scientist in the family, your relatives asked you to help them. They need help, because there are some blanks in the will left to be filled. Here is how the will looks:
Relative #1 will get 1 / ... of the whole heritage,
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.
- 输入
- The only line of input contains the single integer N (1 <= N <= 18).
- 输出
- Output the numbers that the blanks need to be filled (on separate lines), so that the heritage left for the church is minimized.
- 样例输入
-
2
- 样例输出
-
2
3 - 来源
- ural 1108
- 贪心的来想如果只有一个人那就是1/2 , 两个个人就是1/2,1/3 ,还剩下1/6,如果还要分给下一个人,就会1/7 ,还剩1/42,同理下一个人得1/43,然后看出规律了吧,
- 然后我们就涉及到了高精乘,然而普通高精乘是过不了的,所以可以用fft,或者ntt这种黑科技(奇技淫巧)。
- 以下是我ntt
-
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std ;
typedef long long LL ;
const int P = ( << ) + , N = << , G = , NUM = ;
int m , len , l1 , l2 ;
LL a[N] , b[N] , wn[NUM] ; void Init( )
{
scanf( "%d" , &m ) ;
if( m > ) l1 = , l2 = , a[] = , b[] = , len = ;
} LL quick_mod( LL a , LL b , LL m )
{
LL ans = 1ll ;
a %= m ;
while( b )
{
if( b & ) ans = ans * a % m ;
b >>= ;
a = a * a % m ;
}
return ans ;
} void Rader( LL a[] , int n )
{
int j = n >> ;
for( int i = ; i < n - ; ++i )
{
if( i < j ) swap( a[i] , a[j] ) ;
int k = n >> ;
while( j >=k )
{
j -= k ;
k >>= ;
}
if( j < k ) j += k ;
} } void NTT( LL a[] , int n , int on )
{
Rader( a , n ) ;
int id = ;
for( int h = ; h <= n ; h <<= )
{
++id ;
for( int j = ; j < n ; j += h )
{
LL w = ;
for( int k = j ; k < j + ( h >> ) ; ++k )
{
LL u = a[k] % P ;
LL t = w * a[k+(h>>)] % P ;
a[k] = ( u + t ) % P ;
a[k+(h>>)] = ( u - t + P ) % P ;
w = w * wn[id] % P ;
}
}
}
if( on == - )
{
for( int i = ; i < ( n >> ) ; ++i ) swap( a[i] , a[n-i] ) ;
LL inv = quick_mod( n , P - , P ) ;
for( int i = ; i < n ; ++i ) a[i] = a[i] * inv % P ;
} } void Conv( LL a[] , LL b[] , int n )
{
NTT( a , n , ) ;
NTT( b , n , ) ;
for( int i = ; i < n ; ++i )
a[i] = a[i] * b[i] % P ;
NTT( a , n , - ) ;
} void Transfer( LL a[] , int n )
{
for( int i = ; i < n ; ++i )
{
a[i+] += a[i]/ ;
a[i] %= ;
if( a[i] ) l1 = i ;
} ++l1 ;
} void Update( LL b[] , int n )
{
int t = ; l2 = n ;
for( int i = ; i <= n ; ++i )
{
b[i] = a[i] + t ;
t = b[i]/ ; b[i] %= ;
}
if( b[l1] ) ++l2 ; } void print( LL b[] , int n )
{
for( int i = l2 - ; i >= ; --i ) putchar( b[i] + '' ) ;
puts( "" ) ;
} void Length( int l1 , int l2 )
{
while( len <= (l1<<) || len <= (l2<<) ) len <<= ;
} void Getwn( )
{
for( int i = ; i < NUM ; ++i ) wn[i] = quick_mod( G , (P-)/(<<i) , P ) ;
} void Solve( )
{
if( m >= ) puts( "" ) ;
if( m >= ) puts( "" ) ;
if( m <= ) return ;
Getwn( ) ;
for( int i = ; i <= m ; ++i )
{
for( int i = l2 ; i <= len ; ++i ) b[i] = ;
Conv( a , b , len ) ;
Transfer( a , len ) ;
Update( b , l1 ) ;
print( b , l2 ) ;
Length( l1 , l2 ) ;
} } int main( )
{
Init( ) ;
Solve( ) ;
return ;
}
NOIopenjudge 407:Heritage的更多相关文章
- R自动数据收集第一章概述——《List of World Heritage in Danger》
导包 library(stringr) library(XML) library(maps) heritage_parsed <- htmlParse("http://en ...
- Atitit jsr规范有多少个 407个。Jsr规范大全
Atitit jsr规范有多少个 407个.Jsr规范大全 1.1. JCP维护职能是发展和更新.1 1.2. Java技术规范.参考实现(RI).技术兼容包(TCK)1 1.3. JCP维护的规范 ...
- 洛谷P1827 美国血统 American Heritage
P1827 美国血统 American Heritage 54通过 90提交 题目提供者JOHNKRAM 标签USACO 难度普及- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 农夫约翰非 ...
- USACO3.42American Heritage(二叉树)
已知中前 求后序 递归一下 有一些小细节 /* ID: shangca2 LANG: C++ TASK: heritage */ #include <iostream> #include& ...
- USACO 3.4 American Heritage
American Heritage Farmer John takes the heritage of his cows very seriously. He is not, however, a t ...
- HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析
HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无法重复此请求. HTTP 错误 401 401.1 未授权:登录失败 此错误表明传输给服务器的证 ...
- Spring Cloud项目中通过Feign进行内部服务调用发生401\407错误无返回信息的问题
问题描述 最近在使用Spring Cloud改造现有服务的工作中,在内部服务的调用方式上选择了Feign组件,由于服务与服务之间有权限控制,发现通过Feign来进行调用时如果发生了401.407错误时 ...
- LintCode 407: Plus One
LintCode 407: Plus One 题目描述 给定一个非负数,表示一个数字数组,在该数的基础上+1,返回一个新的数组. 该数字按照位权大小进行排列,位权最大的数在列表的最前面. 样例 给定 ...
- (第六场)Heritage of skywalkert 【玄学】
题目链接:https://www.nowcoder.com/acm/contest/144/J 标题:J.Heritage of skywalkert | 时间限制:1 秒 | 内存限制:256M s ...
随机推荐
- matlab vs python
(参考)从下图可以清晰看到matlab和python之间的区别 Python是一种编程语言,但与其他变成语言的不同在于:python具有许多的扩展库(通过import引入) Matlab是集合计算环境 ...
- 关于http客户端常见错误"警告:Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is rec"
在开发过程中,经常得写http客户端测试接口服务,今天在使用过程中出现了这样的一个警告: 警告: Going to buffer response body of large or unknown s ...
- Linux df 命令
Linux df 命令 df(disk free)功能说明:显示磁盘的相关信息.语 法:df [-ahHiklmPT][--block-size=<区块大小>][-t <文件系统类型 ...
- A Full Hardware Guide to Deep Learning
A Full Hardware Guide to Deep Learning Deep Learning is very computationally intensive, so you will ...
- 388A Fox and Box Accumulation
一开始贪心策略想错了! #include<cstdio> #include<algorithm> using namespace std; ]; int main() { in ...
- Unity3D研究院之在MAC上脚本XlsxWriter写入Excel .xlsx格式
原地址:http://www.xuanyusong.com/archives/3011 以前找了很久可以跨平台支持读写Excel的工具,我也试了很多种DLL.可在Windows上各个完美支持,可是在M ...
- 确保客户端可以接收到服务端的异常serviceDebug includeExceptionDetailInFaults="true"
1.为了确保客户端可以接收到服务端反馈的异常 在服务端的配置文件中需要有 <system.serviceModel> <behaviors> <serviceBehavi ...
- PO > Create PO时关于汇率问题需要注意的步骤
为了使得RMB采购的PO在审核时不会提示汇率丢失(如下图),在创建PO时需要注意几个步骤. 1)手动创建PO:在建立PO行之前,应该选择好正确的"地点","币 ...
- Nginx+Keepalived 做负载均衡器
1.安装 keepalived 1 2 3 4 5 6 7 8 9 tar zxvf keepalived-XXXX.tar.gz ./configure --prefix=/usr/local/ ...
- hadoop2.2编程: SequenceFileWritDemo
import java.io.IOException; import java.net.URI; import org.apache.hadoop.fs.FileSystem; import org. ...