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 ...
随机推荐
- 几个.net的GUI控件库
https://github.com/firstfloorsoftware/mui http://wpftoolkit.codeplex.com/ https://github.com/fluentr ...
- 【重要版本】Firefly alpha beta v1.2.2 正式发布
原地址:http://bbs.gameres.com/thread_220175.html firefly 1.2.2 更新 更新内容: 功能添加 1.动态模块更新 2.部分b ...
- javaweb学习总结(三十六)——使用JDBC进行批处理
在实际的项目开发中,有时候需要向数据库发送一批SQL语句执行,这时应避免向数据库一条条的发送执行,而应采用JDBC的批处理机制,以提升执行效率. JDBC实现批处理有两种方式:statement和pr ...
- 告别山寨数据线:USB Type-C加密认证出炉
从去年苹果发布的MacBook首次采用USB Type-C接口开始,这一标准逐渐成为主流,许多旗舰手机慢慢地采用了这种接口.今日,非盈利机构USB开发者论坛(USB-IF)宣布了USB Type-C认 ...
- 第四章 USB库介绍
4.1 USB库函数简介 Luminary Micro公司提供USB处理器的USB库函数,应用在Stellaris处理器上,为USB设备.USB主机.OTG开发提供USB协议框架和API函数,适用于多 ...
- VC 对话框背景颜色、控件颜色(三种方法)
系统环境:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为对话框设置背景颜色.控件颜色 既然MFC对话框不好开发,那么现在我们来开始美化我们的对话框.为对话框设置背景颜色 ...
- RunTime报错的一个原因,以及截图
const char * handle; handle = m_conn->openFile(szRemoteFile,"writeOnly","createTru ...
- WCF - Hosting WCF Service
After creating a WCF service, the next step is to host it so that the client applications can consum ...
- 我的第一个Struts程序
1.程序结构 2.各种文件 LoginAction.java package com.tfj.action; public class LoginAction { private String use ...
- 海量数据的二度人脉挖掘算法(Hadoop 实现)
最近做了一个项目,要求找出二度人脉的一些关系,就好似新浪微博的“你可能感兴趣的人” 中,间接关注推荐:简单描述:即你关注的人中有N个人同时都关注了 XXX . 在程序的实现上,其实我们要找的是:若 U ...