A Very Very Primitive Game


int main()
{
int a, b, c;
cin >> a >> b >> c;
if(c == 0)
{
if(a <= b) puts("Aoki");
else puts("Takahashi");
}
if(c == 1)
{
if(b <= a) puts("Takahashi");
else puts("Aoki");
}
return 0;
}

B Magic 3


int main()
{
int n, s, d;
scanf("%d%d%d", &n, &s, &d);
int flag = 0;
for(int i = 1; i <= n; ++ i)
{
int x, y;
scanf("%d%d", &x, &y);
if(x < s && y > d) flag = 1;
}
puts(flag ? "Yes" : "No");
return 0;
}

C Bowls and Dishes


int n, m, k;
int a[N], b[N];
int c[N], d[N];
int st[N];
int ans; void check()
{
int res = 0;
for(int i = 1; i <= m; ++ i)
if(st[a[i]] && st[b[i]]) res ++;
ans = max(ans, res);
} void dfs(int t)
{
if(t == k + 1) check();
else
{
st[d[t]] ++;
dfs(t + 1);
st[d[t]] --;
st[c[t]] ++;
dfs(t + 1);
st[c[t]] --;
}
} int main()
{
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++ i) scanf("%d%d", &a[i], &b[i]);
scanf("%d", &k);
for(int i = 1; i <= k; ++ i) scanf("%d%d", &c[i], &d[i]);
dfs(1);
printf("%d\n", ans);
return 0;
}

D Staircase Sequences


LL n; int main()
{
IOS;
cin >> n;
LL res = 0;
n *= 2;
for(LL i = 1; i <= n / i; ++ i)
{
if(n % i == 0)
{
LL a = i, b = n / i;
if(a % 2 != b % 2) res ++;
}
}
cout << res * 2 << endl;
return 0;
}

E Magical Ornament


const int N = 2e5 + 10;
const int M = 17; int n, m, k;
struct Edge
{
int to, nxt;
}line[N];
int fist[N], idx;
int c[N], d[N];
int f[1 << M][M];
int w[M][M]; void add(int x, int y)
{
line[idx] = {y, fist[x]};
fist[x] = idx ++;
} void bfs(int x)
{
queue > q;
q.push({x, 0});
while(!q.empty())
{
auto u = q.front(); q.pop();
for(int i = fist[u.first]; i != -1; i = line[i].nxt)
{
int v = line[i].to;
if(d[v] == -1)
{
d[v] = u.second + 1;
q.push({v, d[v]});
}
}
}
} int main()
{
memset(fist, -1, sizeof fist);
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++ i)
{
int a, b;
scanf("%d%d", &a, &b);
add(a, b), add(b, a);
}
scanf("%d", &k);
for(int i = 0; i < k; ++ i) scanf("%d", &c[i]);
for(int i = 0; i < k; ++ i)
{
for(int j = 1; j <= n; ++ j) d[j] = -1;
d[c[i]] = 0;
bfs(c[i]);
for(int j = 0; j < k; ++ j)
w[i][j] = (d[c[j]] == -1) ? INF : d[c[j]];
}
// for(int i = 0; i < k; ++ i)
// {
// for(int j = 0; j < k; ++ j)
// printf("%d ", w[i][j]);
// puts("");
// }
memset(f, 0x3f, sizeof f);
for(int i = 0; i < k; ++ i) f[1 << i][i] = 1; for(int i = 1; i < (1 << k); ++ i)
for(int j = 0; j < k; ++ j) if(i >> j & 1)
for(int t = 0; t < k; ++ t) if((i ^ 1 << j) >> t & 1)
f[i][j] = min(f[i][j], f[i ^ 1 << j][t] + w[t][j]);
int res = INF;
for(int i = 0; i < k; ++ i) res = min(res, f[(1 << k) - 1][i]);
if(res >= INF) puts("-1");
else printf("%d\n", res);
return 0;
}

F Shift and Inversions


int n;
int tr[N];
int a[N]; int lowbit(int x) { return x & -x; }
void add(int x, int v) { for(int i = x; i <= n; i += lowbit(i)) tr[i] += v; }
int sum(int x) { int res = 0; for(int i = x; i; i -= lowbit(i)) res += tr[i]; return res; } int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++ i) { scanf("%d", &a[i]); a[i] ++; }
LL res = 0;
for(int i = 1; i <= n; ++ i)
{
res += sum(n) - sum(a[i]);;
add(a[i], 1);
}
printf("%lld\n", res);
for(int i = 1; i < n; ++ i)
{
res -= sum(a[i] - 1);
res += sum(n) - sum(a[i]);
printf("%lld\n", res);
}
return 0;
}

2021.2.2

AtCoder Beginner Contest 190的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

随机推荐

  1. 二进制安装kubernetes(五) kubelet组件安装

    概述资料地址:https://blog.csdn.net/bbwangj/article/details/81904350 Kubelet组件运行在Node节点上,维持运行中的Pods以及提供kube ...

  2. 一篇文章图文并茂地带你轻松学会 HTML5 storage

    html5 storage api localStorage 和 sessionStorage 是 html5 新增的用来存储数据的对象,他们让我们可以以键值对的形式存储信息. 为什么要有 stora ...

  3. C/C++程序内存的各种变量存储区域和各个区域详解

    转自 https://blog.csdn.net/jirryzhang/article/details/79518408 C语言在内存中一共分为如下几个区域,分别是: 1. 内存栈区: 存放局部变量名 ...

  4. IDEA 安装常用操作一

    关于IDEA的下载,破解自行百度 一.安装完成的常用设置 SDK选择.编译版本的选择,单项目选择,全局选择 maven配置,单项目,全局配置 二.IDEA如何安装lombok https://www. ...

  5. Volatile如何保证线程可见性之总线锁、缓存一致性协议

    基础知识回顾 下图给出了假想机的基本设计.中央处理单元(CPU)是进行算术和逻辑操作的部件,包含了有限数量的存储位置--寄存器(register),一个高频时钟.一个控制单元和一个算术逻辑单元. 时钟 ...

  6. 使用 js 实现十大排序算法: 计数排序

    使用 js 实现十大排序算法: 计数排序 计数排序 refs xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

  7. CSS margin collapsing All In One

    CSS margin collapsing All In One margin collapsing margin 塌陷 / margin 合并 会出现 margin collapsing 的 3 种 ...

  8. npm & cli & node.js

    npm & cli & node.js https://www.npmjs.com/ https://www.npmjs.com/settings/xgqfrms/packages h ...

  9. css & auto height & overflow: hidden;

    css & auto height & overflow: hidden; {overflow: hidden; height: 100%;} is the panacea! {溢出: ...

  10. 封装 React Native 原生组件(iOS / Android)

    封装 React Native 原生组件(iOS / Android) 在 React Native中,有很多种丰富的组件了,例如 ScrollView.FlatList.SectionList.Bu ...