【Atcoder】ARC102 题解
C - Triangular Relationship
题解
枚举一个数%K的值然后统计另两个
代码
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define MAXN 200005
#define pb push_back
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
int N,K;
int cnt[200005];
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
read(N);read(K);
int64 ans = 0;
for(int i = 1 ; i <= N ; ++i) {
cnt[i % K]++;
}
for(int i = 0 ; i < K ; ++i) {
if((K - i) * 2 % K == 0) {
ans += 1LL * cnt[i] * cnt[(K - i) % K] * cnt[(K - i) % K];
}
}
out(ans);enter;
return 0;
}
D - All Your Paths are Different Lengths
题解
感觉自己万分智障,没切掉,被学弟吊着打呀qwq
我们连出一条边全为\(2^0\)到\(2^(r - 1)\)的链出来,\(2^r\)是L的最高位
然后我们通过增加一些点到N的边权X,使得数量为L且合法即可。。
代码
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 - '0' + c;
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
int L,N;
void add(int u,int v,int c) {
out(u);space;out(v);space;out(c);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
read(L);
int r;
for(r = 20 ; r >= 0 ; --r) {
if(L & (1 << r)) break;
}
N = r + 1;out(N);space;int M = r * 2 + __builtin_popcount(L) - 1;out(M);enter;
for(int i = 1 ; i <= N - 1 ; ++i) {
add(i,i + 1,(1 << i - 1));add(i,i + 1,0);
}
for(int i = 1 ; i <= N - 1 ; ++i) {
if(L & (1 << i - 1)) {
L ^= (1 << i - 1);
add(i,N,L);
}
}
}
E - Stop. Otherwise...
题解
计数题
加和的限制相当于有几个数两个中只能出现一个
算一个dp[i][j]表示把i个数分成j段,每一段两种染色方式染色的方案数
然后枚举有多少数用来给两种方式染色,有多少数给怎么放都没事的数
如果有出现两次就不合法的数,那么就先算不存在它的排列,再算存在它一个的排列
代码
#include <bits/stdc++.h>
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define MAXN 1000005
#define mo 999999137
#define pb push_back
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
const int MOD = 998244353;
int fac[4005],inv[4005],invfac[4005],N,K,vis[4005],pw[4005];
int dp[4005][4005];
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int C(int n,int m) {
if(n < m) return 0;
if(n < 0 || m < 0) return 0;
return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
inv[1] = 1;pw[0] = 1;
for(int i = 2 ; i <= 4000 ; ++i) {
inv[i] = mul(inv[MOD % i],MOD - MOD / i);
}
fac[0] = invfac[0] = 1;
for(int i = 1 ; i <= 4000 ; ++i) {
fac[i] = mul(fac[i - 1],i);invfac[i] = mul(invfac[i - 1],inv[i]);
pw[i] = mul(pw[i - 1],2);
}
read(K);read(N);
dp[0][1] = 1;
for(int i = 1 ; i <= N ; ++i) dp[i][1] = 2;
dp[0][0] = 1;
for(int j = 2 ; j <= K ; ++j) {
int s = 1;
dp[0][j] = 1;
for(int i = 1 ; i <= N ; ++i) {
dp[i][j] = inc(mul(s,2),dp[i][j - 1]);
s = inc(s,dp[i][j - 1]);
}
}
for(int i = 2 ; i <= 2 * K ; ++i) {
int cnt = 0,t = 0,rest = 0;
memset(vis,0,sizeof(vis));
for(int j = 1 ; j <= K ; ++j) {
if(!vis[j] && j != i - j && i - j >= 1 && i - j <= K) {vis[j] = vis[i - j] = 1;++cnt;}
}
if(i % 2 == 0) ++t;
rest = K - cnt * 2 - t;
int ans = 0;
for(int j = N ; j >= 0 ; --j) {
ans = inc(ans,mul(dp[j][cnt],rest ? C(N - j - 1 + rest,rest - 1) : (N - j == 0)));
}
if(t) {
for(int j = N - 1; j >= 0 ; --j) {
ans = inc(ans,mul(dp[j][cnt],rest ? C(N - 2 - j + rest,rest - 1) : (N - 1 - j == 0)));
}
}
out(ans);enter;
}
return 0;
}
F - Revenge of BBuBBBlesort!
题解
我们按照逆操作考虑,容易发现是1-N顺序排列
每次交换\(a_{i - 1} < a_{i} < a_{i + 1}\)使得它变成排列p
这样原始排列每次交换的时候相邻两个不会都进行操作,所以排列p如果合法的话一定是
p[i] != i p[i + 1] == i + 1 p[i + 2] != i + 2....这样的排列
所以我们只要对p排列,顺序找出区间l,r保证l + 1,l + 3...r - 1是固定不动的
然后找出剩下往左往右的点,保证往左的点是顺序的,往右的点是顺序的即可
代码
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define enter putchar('\n')
#define space putchar(' ')
#define fi first
#define se second
#define MAXN 300005
//#define ivorysi
#define pii pair<int,int>
using namespace std;
typedef long long int64;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {putchar('-');x = -x;}
if(x >= 10) out(x / 10);
putchar('0' + x % 10);
}
int N;
int p[MAXN],v[MAXN],cnt,id[MAXN],dir[MAXN];
bool vis[MAXN];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(p[i]);
int la = 1;
while(1) {
while(p[la] == la && la <= N) ++la;
if(la > N) break;
int ed = la;
while(1) {
if(ed <= N && ((ed - la) & 1) && p[ed] == ed) ++ed;
else if(ed <= N && !((ed - la) & 1) && p[ed] != ed) ++ed;
else break;
}
--ed;
if(p[ed] == ed) --ed;
if(ed == la) {puts("No");return;}
cnt = 0;
for(int i = la ; i <= ed ; ++i) v[++cnt] = p[i];
sort(v + 1,v + cnt + 1);
for(int i = 1 ; i <= cnt ; ++i) {
if(v[i] != i + la - 1) {puts("No");return;}
}
cnt = 0;
for(int i = la ; i <= ed ; i += 2) {
v[++cnt] = p[i];
id[p[i]] = cnt;
}
sort(v + 1,v + cnt + 1);
for(int i = la ; i <= ed ; i += 2) {
int t = lower_bound(v + 1,v + cnt + 1,p[i]) - v;
if(t <= id[p[i]]) dir[i] = 0;
else dir[i] = 1;
}
int L = 0,R = 0;
for(int i = la ; i <= ed ; i += 2) {
if(dir[i] == 0) {
if(p[i] < L) {puts("No");return;}
L = p[i];
}
else {
if(p[i] < R) {puts("No");return;}
R = p[i];
}
}
la = ed + 1;
}
puts("Yes");
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
【Atcoder】ARC102 题解的更多相关文章
- AtCoder ExaWizards2019题解
AtCoder ExaWizards2019题解 AtCoder (因为代码直接用模板写的,可能有点冗长) A.Regular Triangle 给你三根棍子的长度,问你能否用他们组成等边三角形. 什 ...
- AtCoder | ARC102 | 瞎讲报告
目录 ARC102 前言 正文 传送链接~ ARC102 前言 实在是太菜了....写完第一题就弃疗..感觉T3好歹也是道可做题吧!!然后T2怎么又是进制拆分! 正文 A 题意 给你两个数字\(n,k ...
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- Noip前的大抱佛脚----赛前任务
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...
- AT2370 Piling Up
https://www.luogu.org/jump/atcoder/2370 题解 答案不是\(2^{2m}\)因为每轮的第一次取球可能会不够. 我们可以设\(dp[i][j]\)表示到了第\(i\ ...
- Triple Shift
来源:Atcoder ARC 136 B - Triple Shift (atcoder.jp) 题解:这道题我们不可能去硬模拟(大多数这种题都不能这样去模拟的),然后我们就要去发现特性, 发现把 a ...
- 重修 Slope Trick(看这篇绝对够!)
Slope Trick 算法存在十余载了,但是我没有找到多少拍手叫好的讲解 blog,所以凭借本人粗拙的理解来写这篇文章. 本文除标明外所有图片均为本人手绘(若丑见谅),画图真的不容易啊 qwq(无耻 ...
- AtCoder Regular Contest 094 (ARC094) CDE题解
原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...
- AtCoder ExaWizards 2019 简要题解
AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...
随机推荐
- 标记,上传并下载自己创建的镜像 image
1. 首先使用 docker images 查看已有镜像: 2. 获得 docker-whale 的 IMAGE ID,然后为 docker-whale 镜像 image 打上标签 Tag.使用命令: ...
- 消除JQuery Mobile 列表样式右侧箭头
有时候我们看到JQM上面有一些呈现跟我们要的很像如下面这个Listview效果 程序代码如下: view sourceprint? 1.<ul data-role="listvie ...
- linux系统下开机启动流程
在了解开机启动流程之前,还是得先了解一些磁盘的基本知识.磁盘主要由盘片,机械手臂,磁头,主轴马达构成.盘片就是存储数据的物理单位了.然后盘片上我们可以分成扇区(sector)和柱面(cylinder) ...
- UDP ------ UDP打洞
为什么需要UDP打洞 处于两个不同局域网的主机不能直接进行UDP通信 UDP"打洞"原理 1. NAT分类 根据Stun协议(RFC3489),NAT大致分为下面四类 ...
- 第一次使用 markdown 写博客
Web前端 js 框架(四选一) 有可能的话,学 Vue.js ,React.js ,Angular.js,Awrelia css 学习 Sass 学会 css 的可编程 HTML5 详细语法 Nod ...
- html5 canvas 填充渐变形状
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- iOS 处理缓存的三种方法
缓存处理是个相当头疼的事情,要根据需要综合应用不同的策略.总的来说有以下几种情况: 1.URL缓存,例如社交应用的帖子浏览,要在viewDidAppear:里面进行URL缓存.简单来说就是用NSURL ...
- CF989C A Mist of Florescence (构造)
CF989C A Mist of Florescence solution: 作为一道构造题,这题确实十分符合构造的一些通性----(我们需要找到一些规律,然后无脑循环).个人认为这题规律很巧妙也很典 ...
- C++单链表反转
单链表反转笔记: #include<iostream> #include<string.h> using namespace std; struct ListNode { in ...
- OE中的bitbake使用
OpenEmbedded是一些脚本(shell和python脚本)和数据构成的自动构建系统. 脚本实现构建过程,包括下载(fetch).解包(unpack).打补丁(patch).config ...