AtCoder Beginner Contest 186
A Brick
int n, m;
int main()
{
scanf("%d%d", &n, &m);
printf("%d\n", n / m);
return 0;
}
B Blocks on Grid
int n, m;
int a[N][N];
int main()
{
int sum = 0x3f3f3f3f;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= m; ++ j)
{
scanf("%d", &a[i][j]);
sum = min(sum, a[i][j]);
}
int res = 0;
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= m; ++ j)
{
res += a[i][j] - sum;
}
printf("%d\n", res);
return 0;
}
C Unlucky 7
bool check(int x)
{
int t = x;
while(x)
{
if(x % 10 == 7) return 1;
x /= 10;
}
while(t)
{
if(t % 8 == 7) return 1;
t /= 8;
}
return 0;
}
int main()
{
scanf("%d", &n);
int res = 0;
for(int i = 7; i <= n; ++ i)
if(check(i)) res ++;
printf("%d\n", n - res);
return 0;
}
D Sum of difference
int n;
int a[SZ], b[SZ];
int main()
{
LL sum = 0;
scanf("%d", &n);
for(int i = 1; i <= n; ++ i)
scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; ++ i)
sum += (LL)a[i] * (2 * i - 1 - n);
printf("%lld\n", sum);
return 0;
}
E Throne
\(s + k * x = n * y\)
int n, s, k;
LL exgcd(LL a, LL b, LL &x, LL &y)
{
if(!b)
{
x = 1, y = 0;
return a;
}
LL d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
int main()
{
int __;
scanf("%d", &__);
while(__ -- )
{
LL x, y;
scanf("%d%d%d", &n, &s, &k);
LL d = exgcd(k, n, x, y);
if(s % d) puts("-1");
else
{
x *= - s / d;
LL t = abs(n / d);
printf("%lld\n", (x % t + t) % t);
}
}
return 0;
}
F Rook on Grid
每一次移动可以往下或往右走任意步数,但遇到墙要停,初始位置在(1,1),问走两步以内能够覆盖的路径有多少个格子.
首先考虑第一步向下走,把第二步向右走可以到达的位置统计。
然后考虑第一步向右走,第二步向下走且第一种情况未到达的位置:
即到当前列第一个障碍这些行中,在前面列出现障碍的行数,统计完后把当前列的障碍更新上去,可以用一个树状数组维护.
int tr[N];
int n, m, k;
int row[N];
int column[N];
vector<int> v[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 query(int x) { int res = 0; for(int i = x; i; i -= lowbit(i)) res += tr[i]; return res; }
int main()
{
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i <= n; ++ i) row[i] = m + 1;
for(int i = 1; i <= m; ++ i) column[i] = n + 1;
for(int i = 1; i <= k; ++ i)
{
int x, y;
scanf("%d%d", &x, &y);
row[x] = min(row[x], y);
column[y] = min(column[y], x);
}
LL res = 0;
int flag = 0;
for(int i = 1; i <= n; ++ i)
{
if(flag == 1) { row[i] = 1; continue; }
if(row[i] == 1) { flag = 1; continue; }
res += row[i] - 1;
}
for(int i = 1; i <= n; ++ i) v[row[i]].push_back(i);
for(int i = 1; i <= m; ++ i)
{
if(column[i] == 1) break;
res += query(column[i] - 1);
for(auto j: v[i]) add(j, 1);
}
printf("%lld\n", res);
return 0;
}
2021.1.20
AtCoder Beginner Contest 186的更多相关文章
- Panasonic Programming Contest (AtCoder Beginner Contest 186) E.Throne (数学,线性同余方程)
题意:有围着一圈的\(N\)把椅子,其中有一个是冠位,你在离冠位顺时针\(S\)把椅子的位置,你每次可以顺时针走\(K\)个椅子,问最少要走多少次才能登上冠位,或者走不到冠位. 题解:这题和洛谷那个青 ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】
AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...
- AtCoder Beginner Contest 064 D - Insertion
AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...
随机推荐
- Keywords Search HDU - 2222 AC自动机板子题
In the modern time, Search engine came into the life of everybody like Google, Baidu, etc. Wiskey al ...
- 一篇文章搞懂G1收集器
一.何为G1收集器 The Garbage-First (G1) garbage collector is a server-style garbage collector, targeted for ...
- MongoDB 副本集搭建 & 副本集扩容
副本集的搭建 创建多实例目录 [root@redis03 ~]# mkdir /server/mongodb/2801{7,8,9}/{conf,logs,pid,data} -p 编辑多实例配置文件 ...
- STM32 单片机的USART的奇偶校验 误区(坑)
当STM32的串口配置成带有奇偶校验位的情况下,需要软件校验是否发生奇偶校验错误,硬件只是置起奇偶校验错误标志位,并将错误的数据放到DR寄存器中,同时置起RXEN标志位,如果使能中断还是会正常进入中断 ...
- VuePress 最新教程
VuePress 最新教程 https://vuepress.vuejs.org/ https://github.com/vuejs/vuepress VuePress plugins 插件通常会为 ...
- Vue UI lib missing vue bug
Vue UI lib missing vue bug Error Uncaught TypeError: Cannot read property 'prototype' of undefined a ...
- macOS & PostgreSQL
macOS & PostgreSQL macOS 上安装 PostgreSQL 后为什么会自动创建一个系统用户账号 https://get.enterprisedb.com/postgresq ...
- Wi-Fi 6
Wi-Fi 6 802.11ax https://en.wikipedia.org/wiki/IEEE_802.11ax https://www.wi-fi.org/discover-wi-fi/wi ...
- Koa 洋葱模型
Koa 洋葱模型 let context = { data: [] }; async function middleware1(ctx, next) { console.log('action 001 ...
- js 获取是否为闰年,以及各月的天数 & isLeapYear
js 获取是否为闰年,以及各月的天数 calendar utils isLeapYear const isLeapYear = (year) => { return (year % 4 === ...