A:

题目大意:给你$a,b,c$三条边,可以给任意的边加任意的长度,求最少共加多少长度使得可以构成三角形

题解:排个序,若可以组成,输出$0$,否则输出$c-a-b+1(设a\leqslant b\leqslant c)$

卡点:

C++ Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;} int n, m;
int a[5];
int main() {
for (int i = 0; i < 3; i++) scanf("%d", a + i);
std::sort(a, a + 3);
if (a[0] + a[1] > a[2]) {
puts("0");
} else {
printf("%d\n", a[2] - a[0] - a[1] + 1);
}
return 0;
}

  

B:

题目大意:给你一个数$a(0\leqslant a\leqslant2^{30}-1$,问有多少个数$x(0\leqslant x\leqslant2^{30}-1)$满足$a-(a\oplus x)-x=0$。多组询问

题解:发现满足若$a-(a\oplus x)-x=0$,则$a=(a\oplus x)+x$,即$((a\oplus x)|x)+((a\oplus x)\&x)=a$,若$a$的某一位为$0$,则$x$该位必须为$1$,若为$1$,$x$该位$1,0$均可。所以$ans=2^{\_\_builtin\_popcount(a)}$

卡点:

C++ Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;} int n, m, Tim;
long long a, ans;
int main() {
scanf("%d", &Tim);
while (Tim --> 0) {
scanf("%I64d", &a);
ans = 1;
for (long long i = 0; i < 31; i++) {
if (a & (1ll << i)) {
ans *= 2;
}
}
printf("%I64d\n", ans);
}
return 0;
}

  

C:

题目大意:给你一个字符串,要求你把它重排,使得重排后的字符串的回文字串最多

题解:把原字符串排序,发现这样每一段的回文字串个数是平方级别的,猜测这样最多,然后就过了

卡点:

C++ Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;} int n, m;
char s[100010];
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
std::sort(s + 1, s + n + 1);
printf("%s\n", s + 1);
return 0;
}

  

D:

题目大意:给你一个$n\times m$的矩阵,其中"*"表示墙,"."表示空地,你最多可以按$x$次左和$y$次右,上下没有限制,问最多可以到达几个点

题解:$bfs$,考虑对于到达一个点的不同状态,一定有一个$x,y$比其他的均优(因为要向左一定要向右),可以用优先队列保存(上下的优先级比较高)。

卡点:以为先到达的一定优,于是用普通队列,然后$FST$

C++ Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
const int z[2][4] = {{1, 0, -1, 0}, {0, 1, 0, -1}};
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;} int n, m, r, c, a, b;
char s[2010][2010]; struct node {
int x, y, a, b;
inline bool operator < (const node &rhs) const {return a < rhs.a;}
inline node(int __x = 0, int __y = 0, int __a = 0, int __b = 0) {x = __x, y = __y, a = __a, b = __b;}
};
std::priority_queue<node> q;
bool inq[2010][2010];
inline bool yj(int x, int y) {
if (x < 1 || x > n || y < 1 || y > m) return true;
if (s[x][y] != '.') return true;
return false;
}
int ans;
void bfs(int __x, int __y) {
q.push(node(__x, __y, a, b));
while (!q.empty()) {
node u = q.top(); q.pop();
if (inq[u.x][u.y]) continue;
ans++;
inq[u.x][u.y] = true;
for (int i = 0; i < 4; i++) {
int x = u.x + z[0][i], y = u.y + z[1][i];
if (yj(x, y)) continue;
node tmp = node(x, y, u.a, u.b);
if (i == 1) tmp.b--;
if (i == 3) tmp.a--;
if (tmp.a < 0 || tmp.b < 0) continue;
q.push(tmp);
}
}
}
int main() {
scanf("%d%d", &n, &m);
scanf("%d%d", &r, &c);
scanf("%d%d", &a, &b);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
}
bfs(r, c);
printf("%d\n", ans);
return 0;
}

  

E:

题目大意:交互题。给定一个平面(横、纵坐标均在[0,10^9]之间)。有$n(n\leqslant 30)$个点,每个点都为黑色或白色。但你不知道点的颜色。

要你依次给出点的位置,你选择一个点的位置,交互库给你它的颜色。要求最后输出一条直线,将平面分成$2$部分,使得每部分的点的颜色相同(不能有点落在直线上)。

所有的点的坐标都是整数。

题解:二分答案,第一个点放在最左边,如果一个点和第一个点一样,下一个点就向右移,否则向左移。

卡点:被卡精度,直线经过一个点,$FST$

C++ Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
inline int min(int a, int b) {return a < b ? a : b;}
inline int max(int a, int b) {return a > b ? a : b;} int n, m, l, r;
char s[10];
int get(char *s) {
if (s[0] == 'b') return 1;
return 0;
}
void put(int x, int y) {
printf("%d %d\n", x, y);
fflush(stdout);
fflush(stdin);
}
int main() {
scanf("%d", &n);
l = 0, r = 1000000000;
put(0, 0);
scanf("%s", s);
int op = get(s);
for (int i = 1; i < n; i++) {
int mid = (l + r + 1) >> 1;
put(mid, mid);
scanf("%s", s);
if (op == get(s)) l = mid;
else r = mid;
}
printf("%d %d %d %d\n", l, l + 1, l + 1, l);
return 0;
}

  

[Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) ](A~E)的更多相关文章

  1. 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 ...

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

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

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

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

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

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

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

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

  6. 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. 思路: 差能 ...

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

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

  8. 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, ...

  9. CF Round #516 (Div. 2, by Moscow Team Olympiad)

    前言:依旧菜,\(A\)了\(4\)题,不过这次上蓝了挺开心的. A. Make a triangle! Description 给出\(3\)根木棍,希望用它们拼成三角形,可以将其中的某些木棍增长, ...

随机推荐

  1. MySQL事务隔离级别 解决并发问题

    MySQL事务隔离级别 1. 脏读: 骗钱的手段, 两个窗口或线程分别调用数据库转账表,转账后未提交,对方查看到账后,rollback,实际钱没转. 演示方法: mysql默认的事务隔离级别为repe ...

  2. iOS第三方支付(支付宝)

    使用支付宝进行一个完整的支付功能,大致有以下步骤: 与支付宝签约,获得商户ID(partner)和账号ID(seller) 下载相应的公钥私钥文件(加密签名用) 下载支付宝SDK 生成订单信息 调用支 ...

  3. 返回固定页面的web服务器

    import socket def handle_client(socket_con): """ 接收来自客户端的请求,并接收请求报文,解析,返回 "" ...

  4. 日期格式兼容iOS

    iOS不支持2016-02-11 12:21:12格式的日期 目前Safari可以支持的标准格式: MM-dd-yyyy yyyy/MM/dd MM/dd/yyyy MMMM dd, yyyy MMM ...

  5. LINUX操作系统知识:进程与线程详解

    当一个程序开始执行后,在开始执行到执行完毕退出这段时间内,它在内存中的部分就叫称作一个进程. Linux 是一个多任务的操作系统,也就是说,在同一时间内,可以有多个进程同时执行.我们大家常用的单CPU ...

  6. Python 中关于文件操作的注意事项

    文件操作 #打开文件 f = open('要打开的文件路径',mode = 'r/w/a', encoding = '文件原来写入时的编码') #操作 data = f.read() #读取 f.wr ...

  7. Windows手工创建服务方法

    需要将程序设置成Windows服务的情况,可以利用一下windows自带的sc命令来创建服务. 该命令的基本用法如下:打开cmd命令, 输入如下信息:1 创建服务:sc create SecServe ...

  8. HyperLedger Fabric 1.4 区块链技术形成(1.2)

    在比特币诞生之时,没有区块链技术概念,当人们看到比特币在无中心干预的前提下,还能安全.可靠的运行,比特币网络打开了人们的想象空间:技术专家们开始研究比特币的底层技术,并抽象提取出来,形成区块链技术,或 ...

  9. 20145202马超 《Java程序设计》第五周学习总结

    异常:程序在运行的时候出现不正正常的情况 由来:问题也是可以通过java对不正常情况进行描述后的对象的体现. 问题的划分:(1).严重的问题,java通过error类进行描述,对于error一般不编写 ...

  10. HttpMessageConverter进行加密解密

    技术交流群: 233513714 使用自定义HttpMessageConverter对返回内容进行加密 今天上午技术群里的一个人问” 如何在 Spring MVC 中统一对返回的 Json 进行加密? ...