前言:依旧菜,\(A\)了\(4\)题,不过这次上蓝了挺开心的。

A. Make a triangle!

Description

给出\(3\)根木棍,希望用它们拼成三角形,可以将其中的某些木棍增长,求至少需要增长多少才能拼成一个三角形。

Solution

水题,答案就是最长的木棍长度减去剩下两根木棍的长度和再\(+1\),如果为负则输出\(0\)(即本来就能拼成三角形)。

#include<cstdio>
using namespace std;
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void sw(int &x, int &y)
{
int z = x;
x = y;
y = z;
}
int main()
{
int a, b, c;
a = re();
b = re();
c = re();
if (a < b)
sw(a, b);
if (a < c)
sw(a, c);
if (b < c)
sw(b, c);
if (b + c > a)
printf("0");
else
printf("%d", a - b - c + 1);
}

B. Equations of Mathematical Magic

Description

给出\(a\),求方程\(a - (a\oplus x) - x = 0\)的解的个数(\(\oplus\)为\(xor\)操作)

Solution

找规律,样例很贴心的给出最大数,于是我大力猜结论,核对机房大佬的表后发现正确,非常愉快。

结论:设\(s\)为\(a\)在二进制下\(1\)的个数,则答案就是\(2^s\)。

然而并不会证明

#include<cstdio>
using namespace std;
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
int main()
{
int a, s, i, t = re();
while (t--)
{
s = 0;
a = re();
for (i = 30; ~i; i--)
if (a & (1 << i))
s++;
printf("%d\n", 1 << s);
}
return 0;
}

C. Oh Those Palindromes

Description

给你一个字符串,你可以任意改变串中字符的位置,求构造一个有最多回文子串的字符串。

Solution

构造题,一开始想的很复杂,然后打到一半,机房大佬突然说,只要将相同的字符扔在一起就好了。。

所以这题就是一个\(sort\)的事。。因为我是在打到一半的代码临时改的,所以直接在计数数组上构造了。

#include<cstdio>
using namespace std;
const int N = 1e5 + 10;
const int M = 300;
struct dd{
int s;
char c;
};
dd a[M];
int mp[M], l;
char an[N];
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void re_l()
{
char c = getchar();
for (; c < 'a' || c > 'z'; c = getchar());
for (; c >= 'a' && c <= 'z'; c = getchar())
{
if (!mp[c])
{
a[++l].c = c;
a[l].s = 1;
mp[c] = l;
}
else
a[mp[c]].s++;
}
}
int main()
{
int i, k = 0, j;
re();
re_l();
for (i = 1; i <= l; i++)
for (j = 1; j <= a[i].s; j++)
an[++k] = a[i].c;
for (i = 1; i <= k; i++)
putchar(an[i]);
return 0;
}

D. Labyrinth

Description

一个迷宫,部分格子有障碍物不能走,而你向左和向右走的步数有限制,向上和向下则没有限制,求你一共能到达多少个格子。

Solution

为了到达某个格子是最优情况(剩余向左向右的步数尽量多),可以使用双端队列\(+BFS\),将向上或下走的插入队首,向左或向右的插入队尾,正常\(BFS\)即可。

因为我和机房大佬们一开始想复杂了,我打了\(3.4k\),结果我打挂了。。最后\(1\)分钟的时候,就想着交个暴力算了,于是爆改代码到\(1.6k\),离结束\(15s\)的时候\(pp\)了。

结果因为我恰好改的就是双端队列\(+BFS\)(一开始想的也是基于这个)暴力搜,结果\(A\)了。。。

因为临时爆改,代码很冗长,\(BFS\)里的两个\(if\)和一个\(for\)其实可以合在一起,凑合着看吧。

#include<cstdio>
#include<deque>
using namespace std;
const int N = 2010;
struct dd{
int x, y, mx, my;
};
dd X, Y;
int a[N][N], b[N][N], mo_x[2] = {1, -1}, mo_y[2] = {0, 0}, n, m, s;
deque<dd>q;
inline int re()
{
int x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
p |= c == '-';
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return p ? -x : x;
}
inline void re_l(int i)
{
int k = 0;
char c = getchar();
for (; c != '.' && c != '*'; c = getchar());
for (; c == '.' || c == '*'; c = getchar())
{
a[i][++k] = c == '*' ? -1 : 0;
b[i][k] = a[i][k];
}
}
int main()
{
int i, j, s = 0;
n = re();
m = re();
X.x = re();
X.y = re();
X.mx = re();
X.my = re();
for (i = 1; i <= n; i++)
re_l(i);
a[X.x][X.y] = 1;
q.push_back(X);
while (!q.empty())
{
X = q.front();
q.pop_front();
Y = X;
for (i = 0; i < 2; i++)
{
Y.x = X.x + mo_x[i];
if (!a[Y.x][Y.y] && Y.x > 0 && Y.x <= n && Y.y > 0 && Y.y <= m)
{
a[Y.x][Y.y] = 1;
q.push_front(Y);
}
}
if (X.mx > 0)
{
Y = X;
Y.y--;
Y.mx--;
if (!a[Y.x][Y.y] && Y.x > 0 && Y.x <= n && Y.y > 0 && Y.y <= m)
{
a[Y.x][Y.y] = 1;
q.push_back(Y);
}
}
if (X.my > 0)
{
Y = X;
Y.y++;
Y.my--;
if (!a[Y.x][Y.y] && Y.x > 0 && Y.x <= n && Y.y > 0 && Y.y <= m)
{
a[Y.x][Y.y] = 1;
q.push_back(Y);
}
}
}
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
if (a[i][j] > 0)
s++;
printf("%d", s);
return 0;
}

CF Round #516 (Div. 2, by Moscow Team Olympiad)的更多相关文章

  1. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

    题目链接 A. Make a triangle! 题意 让某段最少增加多少使得构成三角形 思路 让较小两段往最长段去凑 代码 #include <bits/stdc++.h> #defin ...

  2. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth

    http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,…… 求的是最少的步数,所以使用bfs. step=k ...

  3. Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth(重识搜索)

    https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y ...

  4. [Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) ](A~E)

    A: 题目大意:给你$a,b,c$三条边,可以给任意的边加任意的长度,求最少共加多少长度使得可以构成三角形 题解:排个序,若可以组成,输出$0$,否则输出$c-a-b+1(设a\leqslant b\ ...

  5. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins

    http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...

  6. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch

    http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...

  7. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences

    http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能 ...

  8. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal

    http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...

  9. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...

随机推荐

  1. 随机数模块 random模块(1)

    1.取随机小数 import random print(random.random()) # (0,1) print(random.uniform(2,3)) # (n,m) 2.取随机整数 impo ...

  2. 上任com的发布流程

    参考:https://blog.csdn.net/qq_19674905/article/details/80268815 首先把本地代码提交到远程自己的git分支,然后merge request到m ...

  3. with check(转)

    假如我要为一个表中添加一个外键约束.语法如下 alter table  dbo.employee with check add constraint [FK_employeeno]  foreign ...

  4. hibernate中调用query.list()而出现的黄色警告线

    使用hibernate的时候会用到hql语句查询数据库, 那就一定会用到query.list();这个方法, 那就一定会出现一个长长的黄色的警告线, 不管你想尽什么办法, 总是存在, 虽然说这个黄色的 ...

  5. redis 4 集群重启与数据导入

    1.redis 4 平时启用aof db与每天的完整备份. 2.集群状态检查 cluster info 检查集群状态 cluster nodes 检查节点状态 redis-cli -c -p 7000 ...

  6. centos 7 下 cobbler 安装

    一.cobbler 介绍: Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装.重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 W ...

  7. oracle数据库导入导出问题

    场景描述: 1.做一个从UAT到PRD的Schema迁移,UAT环境有sys用户,PRD环境没有sys用户,由于权限限制,没办法使用expdp/impdp,只好选择exp/imp命令: 2.UAT和P ...

  8. Visual C++ 6.0 创建C语言程序

    1 文件-->新建-->”文件“选项卡-->C++ Source File. 2 输入文件名.选择文件位置,点击确定,弹出编辑器窗口. 3 在编辑器窗口中,输入C程序代码,然后保存. ...

  9. TZOJ 2648 小希的迷宫(并查集)

    描述 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一个通道 ...

  10. 【php 之根据函数名称动态调用该函数】

    解释函数:call_user_func()以及函数call_user_func_array() 对于PHP程序员而言,函数是再熟悉不过的事物了,毕竟我们整天都在和PHP内置函数以及我们自定义的函数打交 ...