NAIPC 2018
E. Prefix Free Code
大意: 给定$n$个串, 保证任意一个串都不是另一个串的前缀, 从中选出$k$个串可以拼成$\binom{n}{k}k!$种串. 给定其中一个串, 求这个串的排名.
先用字典树处理一下, 从而转化为给定一个$n$元素中取$k$元素的排列, 求排名.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
const int P = 1e9+;
const int N = 1e6+;
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
int n,k,ch[N][],T,val[N],a[N],tot,cnt,len;
char s[N];
void add(int &o, char *s) {
if (!o) o = ++tot;
if (*s) add(ch[o][*s-'a'],s+);
else val[o] = ;
}
void dfs(int o) {
if (!o) return;
if (val[o]) return val[o] = ++cnt,void();
REP(i,,) dfs(ch[o][i]);
}
void find(int o, char *s) {
if (val[o]) a[++*a]=val[o];
else ++len,find(ch[o][*s-'a'],s+);
} int c[N];
void add(int x, int v) {
for (; x<=n; x+=x&-x) c[x]+=v;
}
int qry(int x) {
int ret = ;
for (; x; x^=x&-x) ret+=c[x];
return ret;
} int main() {
scanf("%d%d",&n,&k);
REP(i,,n) scanf("%s",s),add(T,s);
dfs(T);
scanf("%s",s+);
int m = strlen(s+);
REP(i,,m) len=,find(T,s+i),i+=len-;
int tot = ;
REP(i,n-k+,n) tot = (ll)tot*i%P;
REP(i,,n) c[i] = i&-i;
int ans = ;
REP(i,,k) {
tot = (ll)tot*inv(n-i+)%P;
ans = (ans+(ll)qry(a[i]-)*tot)%P;
add(a[i],-);
}
printf("%d\n",ans);
}
H. Recovery
大意: 给定每行每列和的奇偶性, 要求恢复一个$n\times m$的$01$矩阵, 若有多种方案输出$1$个数最多的, 还有多种的话输出字典序最小的.
先初始化全$1$, 那么就转化为要改变某些行某些列的奇偶性, 如果行列需要改动的个数之差为奇数则无解, 偶数时贪心构造一下.
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=%P;for (a%=P;n;a=a*a%P,n>>=)if(n&)r=r*a%P;return r;}
ll inv(ll x){return x<=?:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=;char p=getchar();while(p<''||p>'')p=getchar();while(p>=''&&p<='')x=x*+p-'',p=getchar();return x;}
//head const int N = ;
int n,m;
vector<int> va,vb;
char ans[N][N],a[N],b[N]; int main() {
scanf("%s%s",a+,b+);
n = strlen(a+);
m = strlen(b+);
REP(i,,n) if (m%==&&a[i]==''||m%==&&a[i]=='') va.pb(i);
REP(i,,m) if (n%==&&b[i]==''||n%==&&b[i]=='') vb.pb(i);
int sza = va.size(), szb = vb.size();
if ((sza-szb)&) return puts("-1"),;
REP(i,,n) REP(j,,m) ans[i][j]='';
if (szb>=sza) {
REP(i,,szb-sza-) ans[][vb[i]] = '';
int now = ;
REP(i,szb-sza,szb-) ans[va[now++]][vb[i]] = '';
}
else {
REP(i,,sza-szb-) ans[va[i]][] = '';
int now = ;
REP(i,sza-szb,sza-) ans[va[i]][vb[now++]] = '';
}
REP(i,,n) puts(ans[i]+);
}
NAIPC 2018的更多相关文章
- 2018. The Debut Album
http://acm.timus.ru/problem.aspx?space=1&num=2018 真心爱过,怎么能彻底忘掉 题目大意: 长度为n的串,由1和2组成,连续的1不能超过a个,连续 ...
- Math.abs(~2018),掌握规律即可!
Math.abs(~2018) 某前端群的入门问题长姿势了,一个简单的入门问题却引发了我的思考,深深的体会到自己在学习前端技术的同时忽略遗忘了一些计算机的基础知识. 对于 JS Math对象没什么可说 ...
- 肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版
肖秀荣8套卷2018pdf下载|2018肖秀荣冲刺8套卷pdf下载电子版 下载链接: https://u253469.ctfile.com/fs/253469-229815828
- 2018年的UX设计师薪酬预测,你能拿多少?
以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 一个经验丰富的设计师完全可以根据地区和专业来可以预期薪酬之间的差距,其中悬殊最高可达80K. 本 ...
- Hello 2018, Bye 2017
2017年过去了,过去一年经历了太多,改变了好多好多,可以说人生进入了另一个阶段,有可能是成熟吧. 回顾2017 去年换了新工作,离开了将近工作了8年的公司,不带走一丝云彩,为其任劳任怨,最后没有任何 ...
- New Life With 2018
2017年转眼过去了.对自己来说.这一大年是迷茫和认知的一年.我的第一篇博客就这样记录下自己的历程吧 一:选择 从进入这一行到现在已经一年多了,2016年11月份就像所有的应届毕业生一样,都贼反感毕业 ...
- 2017 年终总结 & 2018 年度计划
不立几个 Flag,都不知道怎么作死 2017 年度计划完成情况: 1.健身时间不少于350天: 未完成 中断了22天,实际运动 343天 2.至少每个月看一本书: 及格 <切尔诺贝利的 ...
- [总结]-2018 w1
不想总结 2017,过去的就过去吧,不过自己在 2017 年还是收获了很多,最重要的就是赚钱.赚钱还是需要两把刷子,所以,2018 的小目标就是学习数据分析和机器学习.希望自己在这两个领域能搞点事情. ...
- 2018年手机应用UI设计趋势预测
用户需求瞬息万变,而手机软件UI设计为适应变化的用户需求,也相应的发生着变化.但是,这并不意味着用户需求和UI设计趋势就是无迹可寻的.事实上,根据前几年的手机app界面设计变化的特点,尤其是2017年 ...
随机推荐
- [golang][gui]Hands On GUI Application Development in Go【在Go中动手进行GUI应用程序开发】读书笔记03-拒交“智商税”,解密“GUI”运行之道
和老外的原文好像没多大联系了,哈哈哈,反正是读书笔记,下面的内容也是我读此书中的历程,也写进来吧.不过说实话,这框架的作者还挺对我脾气的,哈哈哈. 拒交“智商税”,解密“GUI”运行之道 我很忙 项目 ...
- 小程序使用npm安装第三方包
安装vant 小程序UI库 进到小程序目录,在地址栏中cmd 进入DOS界面 npm init -f 安装vant 小程序UI库 npm i vant-weapp -S --production ...
- PSQLException: An I/O error occurred while sending to the backend.
postgresql批量新增数据时,批量插入的数据量太大了,造成了IO异常 只能把这么多数据先进行分割,再批量插入,但是感觉这种方式不是最优解,先暂时顶着,具体List分割方式如下: package ...
- [Beta]Scrum Meeting#1
github 本次会议项目由PM召开,时间为5月6日晚上10点30分 时长15分钟 任务表格 人员 昨日工作 下一步工作 木鬼 beta初步计划 撰写博客整理文档 swoip 前端改进计划 模块松耦合 ...
- vs2017+qt5.x编译32位应用<转>
原文地址:https://www.cnblogs.com/woniu201/p/10862170.html 概述 最近有同学私信我,问如何使用vs2017+qt5.10编译出32位的应用,需要使用ms ...
- android : 解决android无法使用sun.misc.BASE64Encoder sun.misc.BASE64Decoder 的问题, 无需添加rt.jar
一共包含: BASE64Decoder.java BASE64Encoder.java CEFormatException.java CEStreamExhausted.java CharacterD ...
- linux系统错误码大全
#define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #defi ...
- 行车记录仪 MyCar Recorder (转)
行车记录仪 MyCar Recorder
- BGP MPLS IP V匹N基本概念
BGP/MPLS IP VPN基本概念 Site 在介绍VPN时经常会提到"Site",Site(站点)的含义可以从下述几个方面理解: · Site是指相互之间具备IP连通性的一组 ...
- 爬虫中Selenium和PhantomJS
Selenium Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,类型像我们玩游戏用的按键精灵,可以按指定的命令自动操作,不同是Selenium 可以直接运行在浏览器上, ...