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 ...
随机推荐
- 一篇文章图文并茂地带你轻松学完 JavaScript 设计模式(二)
JavaScript 设计模式(二) 本篇文章是 JavaScript 设计模式的第二篇文章,如果没有看过我上篇文章的读者,可以先看完 上篇文章 后再看这篇文章,当然两篇文章并没有过多的依赖性. 5. ...
- Vue的七种传值方式
目录 1,父传子 2,子传父 3,兄弟组件传值 4,父组件使用子组件的数据和方法 5,子组件使用父组件的数据和方法 6,Vuex传值 6.1,定义store 6.2,挂载 6.3,使用 7,路由传值 ...
- Hexo之更换背景及透明度
Hexo之更换背景及透明度 引入方式 首先,介绍一下引入方式,外部导入css文件,不影响内部配置. 1.创建css文件 创建一个css文件移动到\themes\butterfly\source\css ...
- bzoj1013球形空间产生器sphere 高斯消元(有系统差的写法
Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧毁 ...
- 009.NET5_程序的发布运行
发布 相差了web.config文件 脚本启动 cmd,进入程序根目录. 带参启动 其实,最终与web.config中效果一样
- h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated
Reference 问题 ... h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype ...
- js sort tricks All In One
js sort tricks All In One js 排序技巧 const arr = [ { label: 'False 1 ', disabled: false, }, { label: 'F ...
- Python errors All In One
Python errors All In One SyntaxError: invalid character in identifier \u200b, ZERO WIDTH SPACE https ...
- Cocos Creator 游戏开发
Cocos Creator 游戏开发 https://www.cocos.com/products#CocosCreator 一体化编辑器: 包含了一体化.可扩展的编辑器,简化了资源管理.游戏调试和预 ...
- You, Me & SVG!
You, Me & SVG! SVG refs code-school-you-me-svg https://www.youtube.com/watch?v=a8Y0L5q63y8 https ...