ARC 068

C - X: Yet Another Die Game

显然最多的就是一次6一次5

最后剩下的可能需要多用一次6或者6和5都用上

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 3005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
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);
}
int64 s,n;
void Solve() {
read(s);
n = (s / 11) * 2;
s %= 11;
if(s > 0 && s <= 6) n += 1;
if(s > 6) n += 2;
out(n);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

D - Card Eater

就是奇数的卡片最后肯定能全消掉,只剩一个

偶数的卡片最后会剩两个,看看两两配对,最后会不会剩一个,剩一个证明肯定需要少一种数,否则就是原来序列中不同的数的个数

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
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);
}
map<int,int> zz;
int N;
int a[MAXN];
void Solve() {
read(N);
int cnt = 0,p = 0;
for(int i = 1 ; i <= N ; ++i) {
read(a[i]);
zz[a[i]]++;
}
for(auto t : zz) {
++cnt;
if(t.se % 2 == 0) p ^= 1;
}
out(cnt - p);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

E - Snuke Line

对于一个d来说,我们把大于等于d的区间全部删掉

然后给\(l - 1\)标记成+1,\(r\)标记成-1,这些区间里能被d访问到的个数是

d - 1的前缀和2d - 1的前缀和,3d - 1的前缀和....

直接树状数组维护就好了

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
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,M;
int tr[MAXN],ans[MAXN];
pii p[MAXN];
int lowbit(int x) {return x & (-x);}
void insert(int x,int v) {
++x;
while(x <= M + 1) {
tr[x] += v;
x += lowbit(x);
}
}
int query(int x) {
int v = 0;++x;
while(x > 0) {
v += tr[x];
x -= lowbit(x);
}
return v;
}
void Solve() {
read(N);read(M);
for(int i = 1 ; i <= N ; ++i) {
read(p[i].fi);read(p[i].se);
--p[i].fi;
insert(p[i].fi,1);insert(p[i].se,-1);
}
sort(p + 1,p + N + 1,[](pii a,pii b){return a.se - a.fi < b.se - b.fi;});
int id = N;
int cnt = 0;
for(int i = M ; i >= 1 ; --i) {
while(id >= 1 && p[id].se - p[id].fi >= i) {
insert(p[id].fi,-1);insert(p[id].se,1);
++cnt;--id;
}
ans[i] = cnt;
int t = i;
while(t <= M) {
ans[i] += query(t - 1);
t += i;
}
}
for(int i = 1 ; i <= M ; ++i) {out(ans[i]);enter;}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

F - Solitaire

大意是有一个双端队列,从1到N往里面扔数,再从队首或者队尾取数,要求第K个必须是1,求方案数

这个就看什么样的是合法的,我们发现如果当前没选到1,已经选了i个数,最小的是j,我们要么就选一个比j还小的,要么选一个当前没选过的最大的

这个可以用前缀和优化去dp

当选到第k个之后,就是剩下的序列要么选最大的,要么选最小的,看看乘上2的多少次方就行了

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 300005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
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 MOD = 1000000007;
int K,N;
int dp[2005][2005],sum[2005];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void Solve() { read(N);read(K);
dp[0][N + 1] = 1;
for(int i = 1 ; i <= K ; ++i) {
sum[N + 2] = 0;
for(int j = N + 1 ; j >= 1 ; --j) sum[j] = inc(sum[j + 1],dp[i - 1][j]);
for(int j = 1 ; j <= N ; ++j) {
if(i == K && j != 1) continue;
if(i < K && j == 1) continue;
dp[i][j] = sum[j + 1];
if((N - j + 1) > (i - 1)) dp[i][j] = inc(dp[i][j],dp[i - 1][j]);
}
}
int t = 1;
for(int i = 1 ; i < N - K ; ++i) {
t = mul(t,2);
}
out(mul(dp[K][1],t));enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}

【AtCoder】ARC068的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. poj 2762

    Tarjan + TopsortTarjan 缩点Topsort 判断 Topsort 判断:在DAG中若初始状态下存在多于1个入度为0的点则说明这些 入度为0的点之间不会有路径可达若不存在入度为0的 ...

  2. CF1153E Serval and Snake【构造】

    题目链接:洛谷 这道题是很久以前NTF跟我说的,现在想起来把它做了... 我们发现,如果蛇的两头都在矩形里或矩形外,则询问为偶数,否则为奇数. 所以我们询问每一行和每一列,就能知道蛇的两头的横纵坐标了 ...

  3. bash基础之三配置文件

    一.shell的两种登录方式: 1.交互式登录:(1)直接通过终端输入账号密码登录(2)使用“su - UserName” 或“su -l Username”切换的用户执行顺序:/etc/profil ...

  4. 一句话题解&&总结

    CF79D Password: 差分.两点取反,本质是匹配!最短路+状压DP 取反是套路,匹配是发现可以把操作进行目的化和阶段化,从而第二次转化问题. 且匹配不会影响别的位置答案 sequence 计 ...

  5. Ryu控制器安装部署和入门

    Ryu官网简介,原滋原味 Ryu is a component-based software defined networking framework. Ryu provides software c ...

  6. Java并发指南9:AQS共享模式与并发工具类的实现

    一行一行源码分析清楚 AbstractQueuedSynchronizer (三) 转自:https://javadoop.com/post/AbstractQueuedSynchronizer-3 ...

  7. CentOS7.4中配置jdk环境

    参考:https://www.linuxidc.com/Linux/2016-09/135556.htm 1.下载jdk 首先创建安装包放置位置 mkdir -p /usr/local/java 然后 ...

  8. 导出和导入eclipse中通过help安装的插件的地址

    这种方式和在线安装一样,唯一方便的就是不用再去翻找软件下载地址 导出已安装的插件: 打开Window ——>Preferences ——>Install/Update——>Avail ...

  9. 【Java】异常的平行处理

    Java对异常的处理,是平行的处理,进行了特定异常的处理后,便不会进入通用异常的处理,出现了未曾显式捕获的异常时,才会进入最宽泛的Excption处理. 具体请看下面代码: package com.h ...

  10. busybox中memdev的使用方法

    busybox中已经集成了devmem工具,你可以配置busybox即可. 在busybox的杂项中找到: CONFIG_USER_BUSYBOX_DEVMEM: devmem is a small ...