North American Invitational Programming Contest (NAIPC) 2016
(待补)
A. Fancy Antiques
爆搜。
B. Alternative Bracket Notation
C. Greetings!
D. Programming Team
0/1分数规划 + 树上依赖型背包。
E. K-Inversions
将 A 和 B 的相对位置看做多项式,用FFT,最后统计系数。
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0); struct comp{
double r,i;
comp(double _r=0, double _i=0):r(_r),i(_i) {}
comp operator + (const comp& x) { return comp(r+x.r, i+x.i); }
comp operator - (const comp& x) { return comp(r-x.r, i-x.i); }
comp operator * (const comp& x) { return comp(r*x.r-i*x.i, r*x.i+i*x.r); }
}; void FFT(comp a[], int n, int t)
{
for(int i=1, j=0; i < n-1; i++)
{
for(int s=n; j^=s>>=1, ~j&s;);
if(i<j)
swap(a[i],a[j]);
}
for(int d=0; (1<<d)<n; d++)
{
int m=1<<d, m2=m<<1;
double o=pi/m*t;
comp _w(cos(o),sin(o));
for(int i=0; i<n; i+=m2)
{
comp w(1,0);
for(int j=0; j<m; j++)
{
comp& A=a[i+j+m], &B=a[i+j], t=w*A;
A=B-t;
B=B+t;
w=w*_w;
}
}
}
if(t == -1)
for(int i=0; i<n; i++)
a[i].r=floor(a[i].r/n+0.5);
} const int maxn = 3e6 + 100;
comp A[maxn], B[maxn];
char str[maxn];
int len; int main()
{
scanf("%s", str);
len = strlen(str);
for(int i = 0; i < len; ++i)
{
if(str[i] == 'B')
A[i].r=0, B[len-i].r=1;
else
A[i].r=1, B[len-i].r=0;
}
int tmp = 1;
while(tmp < 2*len)
tmp*=2;
swap(len, tmp);
FFT(A, len, 1);
FFT(B, len, 1);
for(int i = 0; i < len; ++i)
A[i] = A[i]*B[i];
FFT(A, len, -1);
for(int i = tmp+1; i < 2*tmp; ++i)
{
printf("%.0f\n", A[i].r);
} return 0;
}
F. Mountain Scenes
dp[i][j]表示前 i 块区域总共用的长度为 j 。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 100 + 100;
const int MOD = 1e9 + 7;
int dp[maxn][10010]; int main()
{
int n, w, h;
scanf("%d%d%d", &n, &w, &h);
dp[0][0] = 1; for (int i = 1; i <= w; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= h; k++)
{
if (j+k > n) break;
dp[i][j+k] += dp[i-1][j];
if (dp[i][j+k] >= MOD) dp[i][j+k] -= MOD;
} LL ans = 0;
for (int i = 1; i <= n; i++) ans += dp[w][i];
for (int i = 1; i <= h; i++)
if (i * w <= n) ans--;
printf("%lld\n", (ans+MOD) % MOD);
}
G. Symmetry
H. Jewel Thief
I. Tourists
LCA爆。复杂度O(nlog2n)。
J. Whiteboard
K. YATP
North American Invitational Programming Contest (NAIPC) 2016的更多相关文章
- North American Invitational Programming Contest (NAIPC) 2017
(待补) A. Pieces of Parentheses 将括号处理完成后排序,方式参加下面的博客.然后做一遍背包即可. 2018 Multi-University Training Contest ...
- The North American Invitational Programming Contest 2017 题目
NAIPC 2017 Yin and Yang Stones 75.39% 1000ms 262144K A mysterious circular arrangement of black st ...
- The North American Invitational Programming Contest 2018 D. Missing Gnomes
A family of nn gnomes likes to line up for a group picture. Each gnome can be uniquely identified by ...
- The North American Invitational Programming Contest 2018 H. Recovery
Consider an n \times mn×m matrix of ones and zeros. For example, this 4 \times 44×4: \displaystyle \ ...
- The North American Invitational Programming Contest 2018 E. Prefix Free Code
Consider nn initial strings of lower case letters, where no initial string is a prefix of any other ...
- North American Invitational Programming Contest 2018
A. Cut it Out! 枚举第一刀,那么之后每切一刀都会将原问题划分成两个子问题. 考虑DP,设$f[l][r]$表示$l$点顺时针一直到$r$点还未切割的最小代价,预处理出每条边的代价转移即可 ...
- 2014 ACM-ICPC Beijing Invitational Programming Contest
点击打开链接 Happy Reversal Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld J ...
- 训练20191007 2017-2018 ACM-ICPC Latin American Regional Programming Contest
2017-2018 ACM-ICPC Latin American Regional Programming Contest 试题地址:http://codeforces.com/gym/101889 ...
- 2017-2018 ACM-ICPC Latin American Regional Programming Contest PART (11/13)
$$2017-2018\ ACM-ICPC\ Latin\ American\ Regional\ Programming\ Contest$$ \(A.Arranging\ tiles\) \(B. ...
随机推荐
- PyQt学习笔记
---------------个人学习笔记--------------- 1.QtWidgets.QApplication.instance().quit() 方法可退出当前窗体 2.self.Qla ...
- 用CSS控制图片大小显示的方法
图片自动适应大小是一个非常常用的功能,在进行制作的时候为了防止图片撑开容器而对图片的尺寸进行必要的控制,我们可不可以用CSS控制图片使它自适应大小呢? 可以通过按比例缩小或者放大到某尺寸(自己指定), ...
- Ubuntu下eclipse无法识别手机驱动(以小米2S为例子)
google官方开发向导里对Android手机已经设置了允许安装非market程序,并且处于usb调试模式,但是仍然在usb连接电脑后无法被识别的问题作了解释. 在Ubuntu Linux环境下需要添 ...
- 分享到qq空间等代码
<!-- Baidu Button BEGIN --><div id="bdshare" class="bdshare_t bds_tools get- ...
- 软件License设计
如何保护软件版权,最常用的办法就是设计一套license验证框架. 1.我们的常规需求如下: .可以限制软件只能在一台机器上使用: 目前很多软件都是一机一码的销售,软件换一台机器则不能使用,想要几台机 ...
- Dll注入:Ring3 层 APC注入
APC,即Asynchronous procedure call,异步程序调用APC注入的原理是:在一个进程中,当一个执行到SleepEx()或者WaitForSingleObjectEx()时,系统 ...
- hihocoder 1109 堆优化的Prim算法
题目链接:http://hihocoder.com/problemset/problem/1109 , 最小生成树 + 堆优化(优先队列). 可以用优先队列,也可以自己手动模拟堆,为了练手,我两种都试 ...
- DBMS事务的四大特性
数据库事务的四大特性分别是:原子性.一致性.隔离性和持久性. 特性 说明 实现 一致性 在一个事务执行之前和执行之后数据库都必须处于一致性状态.假如数据库的状态满足所有的完整性约束,也可以说数据库是一 ...
- linux 命令——42 kill (转)
Linux 中的kill命令用来终止指定的进程(terminate a process)的运行,是Linux下进程管理的常用命令.通常,终止一个前台进程可以 使用Ctrl+C键,但是,对于一个后台进程 ...
- linux命令 ——目录
开始详细系统的学习linux常用命令,坚持每天一个命令,所以这个系列为每天一个linux命令.学习的主要参考资料为: 1.<鸟哥的linux私房菜> 2.http://codingstan ...