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. java基础 File 递归删除文件夹中所有文件文件夹 目录(包含子目录)下的.java文件复制到e:/abc文件夹中, 并统计java文件的个数

    File 递归删除文件夹中所有文件文件夹 package com.swift.kuozhan; import java.io.File; import java.util.Scanner; /*键盘录 ...

  2. 爬虫学习(十九)——Scrapy的学习及其使用

    Scrapy框架的介绍 Scrapy,非常的强悍,通过python语言编写的,非常知名的爬虫框架 框架工作流程 框架流程图 基本工作流程; 1.引擎向spiders要url 2.引擎将要爬取的url给 ...

  3. JSONArray.fromObject不执行且不报错问题的解决

    今天在写javaweb工程的时候需要向前台传json格式的数据,用到了json-lib-2.4-jdk15.jar等一系列包,然而却出现如下状况: CityBean是一个javaBean,我们看到,控 ...

  4. openldap完整版本搭建记录

    文档信息 目        的:搭建一套完整的OpenLDAP系统,实现账号的统一管理.                     1:OpenLDAP服务端的搭建                   ...

  5. 微信公众号支付java版本

    回调函数 @RequestMapping("/toPay") public String toPay(HttpServletRequest request, HttpServlet ...

  6. tcl之文件操作

  7. 【异常】The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    异常错误:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone ...

  8. [Bzoj3991]寻宝游戏(dfs序+set)

    Description 题目链接 Solution 用set按dfs序维护当前的宝物序列,那么答案为相邻2个点的距离加上头尾2个的距离 Code #include <cstdio> #in ...

  9. Android 数据库中的数据给到ListView

    前言:因为之前学的都是用一个自己定义的类,完成将某一个bean中的数据直接获取,而实际中通常是通过数据库来得到的,总之,最终就是要得到数据.提一下最重要的东西,我把它叫做代理,如同一个校园代理,没有他 ...

  10. 6.Mongodb索引

    1.索引 2.索引的命令