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 题解的更多相关文章

  1. AtCoder ExaWizards2019题解

    AtCoder ExaWizards2019题解 AtCoder (因为代码直接用模板写的,可能有点冗长) A.Regular Triangle 给你三根棍子的长度,问你能否用他们组成等边三角形. 什 ...

  2. AtCoder | ARC102 | 瞎讲报告

    目录 ARC102 前言 正文 传送链接~ ARC102 前言 实在是太菜了....写完第一题就弃疗..感觉T3好歹也是道可做题吧!!然后T2怎么又是进制拆分! 正文 A 题意 给你两个数字\(n,k ...

  3. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  4. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

  5. AT2370 Piling Up

    https://www.luogu.org/jump/atcoder/2370 题解 答案不是\(2^{2m}\)因为每轮的第一次取球可能会不够. 我们可以设\(dp[i][j]\)表示到了第\(i\ ...

  6. Triple Shift

    来源:Atcoder ARC 136 B - Triple Shift (atcoder.jp) 题解:这道题我们不可能去硬模拟(大多数这种题都不能这样去模拟的),然后我们就要去发现特性, 发现把 a ...

  7. 重修 Slope Trick(看这篇绝对够!)

    Slope Trick 算法存在十余载了,但是我没有找到多少拍手叫好的讲解 blog,所以凭借本人粗拙的理解来写这篇文章. 本文除标明外所有图片均为本人手绘(若丑见谅),画图真的不容易啊 qwq(无耻 ...

  8. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  9. AtCoder ExaWizards 2019 简要题解

    AtCoder ExaWizards 2019 简要题解 Tags:题解 link:https://atcoder.jp/contests/exawizards2019 很水的一场ARC啊,随随便便就 ...

随机推荐

  1. 简单的sql分组统计

    一个记录员工打卡时间的表,只有两个有效字段 员工名称,打卡时间,现在要统计某一天中,每个员工的打卡次数.最早打卡时间.最晚打卡时间,问sql怎么写? 其实这个sql很简单, 1.首先要明确既然是按每个 ...

  2. 14.会场安排问题(L4)

    时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就是安排学校 ...

  3. openstack项目【day23】:虚拟化介绍

    本节内容 一 什么是虚拟化 二 为何要学习虚拟化 三 虚拟化技术主要分类(了解) 四 平台虚拟化技术又可以细分(了解) 一 什么是虚拟化 虚拟化说白了就是本来是一个完整的资源,切分或者说虚拟成多份,让 ...

  4. C语言复习---二维数组和二级指针的关系:没关系,别瞎想(重点)

    前提:一维数组和一维指针为什么可以替换使用? ] = { , , }; int *p = a; ; i < ; i++) printf("%d ", *(p + i)); 上 ...

  5. Matrix67|自由职业者,数学爱好者

    Matrix67|自由职业者,数学爱好者 介绍一下你自己和所做的工作. 我叫顾森,网名 Matrix67,长住北京的重庆人,目前没有固定的职业.一会儿当当码农,一会儿做做编辑,一会儿教教数学,一会儿写 ...

  6. 基于canvas将图片转化成字符画

    字符画大家一定非常熟悉了,那么如何把一张现有的图片转成字符画呢?HTML5让这个可能变成了现实,通过canvas,可以很轻松实现这个功能.其实原理很简单:扫描图片相应位置的像素点,再计算出其灰度值,根 ...

  7. 20155321 2016-2017-2 《Java程序设计》第八周学习总结

    20155321 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 创建Logger对象 static Logger getLogger(String name ...

  8. 使用js获取浏览器地址栏里的参数

    用JS获取地址栏参数的方法(超级简单) 方法一:采用正则表达式获取地址栏参数:( 强烈推荐,既实用又方便!) function GetQueryString(name) { var reg = new ...

  9. 第10月第1天 iOS crash

    1. find /Applications/Xcode6.1.app -name symbolicatecrash -type f tempdeMac-mini:crash temp$ dwarfdu ...

  10. [转]避免头文件重复包含以及#ifndef 与 #program once 的区别

    为了避免同一个文件被include多次,C/C++中有两种方式,一种是#ifndef方式,一种是#pragma once方式.在能够支持这两种方式的编译器上,二者并没有太大的区别,但是两者仍然还是有一 ...