AtCoder Beginner Contest 126 解题报告
突然6道题。有点慌。比赛写了五个。罚时爆炸。最后一个时间不太够+没敢写就放弃了。
两道题奇奇怪怪的WJ和20/20。今天的评测机是怎么了。
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} const int N = ;
char s[N]; int main() {
int n = read(), k = read();
scanf("%s", s + );
for (int i = ; i <= n; i++) {
if (i == k) putchar(s[i] + 'a' - 'A');
else putchar(s[i]);
}
puts("");
return ;
}
因为写了 a>=0 WA了两发。
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} const int N = 1e5 + ;
char s[]; int main() {
cin >> s;
int ret = ;
int a = (s[] - '') * + s[] - '';
if (a <= && a > ) ret++;
a = (s[] - '') * + s[] - '';
if (a <= && a > ) ret += ;
if (ret == ) puts("NA");
if (ret == ) puts("MMYY");
if (ret == ) puts("YYMM");
if (ret == ) puts("AMBIGUOUS");
return ;
}
第一次在这上面写概率题。
精度要求居然到了1e-9!
果断long double 但发现就是过不了第二个样例 最后答案-1e-10就好了
题意:有$n$种取值(1到$n$),每次有1/2的概率能使这个值乘以2,问最后值大于等于$K$的概率
思路:$bin\left[i\right]$表示2的i次,然后从后往前找到第一个$i\times bin\left[ j\right] <k$的 这样$2^{j+1}$必定大于等于$K$了 到这里的概率就是$\dfrac {1}{2^{j+1}}$
对于$i\geq k$的部分 对答案的贡献就是1
最后答案除以$n$再减去1e-10就ok了
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} int bin[]; int main() {
bin[] = ;
for (int i = ; i < ; i++) bin[i] = bin[i - ] * ;
int n = read(), k = read();
long double ans = ;
for (int i = ; i <= n; i++) {
for (int j = ; j >= ; j--) {
if (1LL * bin[j] * i < 1LL * k) {
ans += (long double) / (long double)bin[j + ];
cout << j + << '\n';
break;
}
}
}
if (n >= k) ans += (long double)(n - k + );
printf("%.10Lf\n", (ans / (long double)n - 1e-));
return ;
}
题意:对一棵树上的节点染成黑或白色,所有相同颜色的点对,他们之间的距离必须为偶数
思路:直接DFS,距离为偶数就涂成一样的,为奇数就涂成相反的,这样的结果一定是对的,因为偶数+偶数结果还是偶数,这样三个结点会被涂成一样的,奇数+奇数=偶数 会被涂成0 1 0 这样结果还是对的
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} const int N = 1e5 + ;
bool vis[N];
int n, head[N], cnt, ans[N];
struct Edge { int v, next, w; } edge[N * ];
inline void add(int u, int v, int w) {
edge[++cnt].v = v; edge[cnt].w = w; edge[cnt].next = head[u]; head[u] = cnt;
edge[++cnt].v = u; edge[cnt].w = w; edge[cnt].next = head[v]; head[v] = cnt;
} void dfs(int u, int c) {
ans[u] = c;
vis[u] = ;
for (int i = head[u]; i; i = edge[i].next) {
int v = edge[i].v;
if (vis[v]) continue;
if (edge[i].w & ) dfs(v, c ^ );
else dfs(v, c);
}
} int main() {
n = read();
for (int i = ; i < n - ; i++) {
int u = read(), v = read(), w = read();
add(u, v, w);
}
dfs(, );
for (int i = ; i <= n; i++) printf("%d\n", ans[i]);
return ;
}
题意:有n个数,要不为1要不为2,现在有m对关系 $a_{i} + b_{i} + z_{i}$是偶数,问最少要知道几个数,能知道所有的数。
思路:其实就是问这些数组成了几个连通块,一个连通块里面知道一个数之后其他的数就都能知道了,画个图就知道了。DFS即可
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} const int N = 1e5 + ;
struct Edge { int v, next;} edge[N * ];
bool vis[N];
int n, m, cnt, head[N];
inline void add(int u, int v) {
edge[++cnt].v = v; edge[cnt].next = head[u]; head[u] = cnt++;
edge[++cnt].v = u; edge[cnt].next = head[v]; head[v] = cnt++;
}
void dfs(int u) {
vis[u] = ;
for (int i = head[u]; i; i = edge[i].next) {
int v = edge[i].v;
if (!vis[v]) dfs(v);
}
} int main() {
n = read(), m = read();
for (int i = ; i < m; i++) {
int a = read(), b = read(); int c = read();
add(a, b);
}
int ans = ;
for (int i = ; i <= n; i++) {
if (!vis[i]) {
ans++;
dfs(i);
}
}
printf("%d\n", ans);
return ;
}
题意:给一个数n和k,问能不能构造出一个序列 满足 :
数字0到$2^{n} - 1$每个数出现两次且每对相同数字之间的区间异或和为k
思路:又是区间异或和的题。ABC121的D也是区间异或和的题 传送门
结论 n % 4 == 3时 $f(n)$ = 0 $f(n)$表示区间[0,n]的异或和
所以n = 1的时候需要特判 因为$2^{n} - 1$ = 1 1模4不等于3
k = 0的时候可以粘一下样例 不等于0的时候输出-1就行了
因为两个1之间的异或和肯定是0
当 $k\geq 2^{n}$的时候,不可能有几个数的异或和为k 因为k的最高位比$2^{n}-1$要高一位
所以输出-1
其他情况下
构造性出序列
0 1 2 ... k $2^{n} - 1$ ... 2 1 0 k
对于这个序列中除了k的所有相同的数对
中间均为2个相同的数和一个k 所以异或和为k
而对于k和另一个k 中间是 0 ~ $2 ^{n} - 1$少了k
又因为$f(2^{n}-1)$ = 0 所以少了一个k 区间异或和也为k
所以这样的构造是对的(表示想不到。)
#include <bits/stdc++.h>
using namespace std; inline int read() {
int x = , f = ; char ch = getchar();
while (ch < '' || ch > '') { if (ch == '-') f = -; ch = getchar(); }
while (ch >= '' && ch <= '') { x = x * + ch - ; ch = getchar(); }
return x * f;
} int main() {
int n = read(), k = read();
if (k >= ( << n)) {
puts("-1");
return ;
}
if (n == ) {
if (k != ) puts("-1");
else puts("0 1 1 0");
return ;
}
for (int i = ; i < ( << n); i++) if (i != k) printf("%d ", i);
printf("%d ", k);
for (int i = ( << n) - ; i >= ; i--) if (i != k) printf("%d ", i);
printf("%d", k);
puts("");
return ;
}
AtCoder Beginner Contest 126 解题报告的更多相关文章
- AtCoder Beginner Contest 122 解题报告
手速选手成功混进rated only里面的前30名,但是总排名就到110+了... A - Double Helix #include <bits/stdc++.h> #define ll ...
- AtCoder Beginner Contest 146解题报告
题目地址 https://atcoder.jp/contests/abc146/tasks 感觉没有什么有意思的题... 题解 A #include <bits/stdc++.h> usi ...
- Atcoder Beginner Contest 124 解题报告
心态爆炸.本来能全做出来的.但是由于双开了Comet oj一个比赛,写了ABC就去搞那个的B题 还被搞死了. 回来写了一会D就过了.可惜比赛已经结束了.真的是作死. A - Buttons #incl ...
- AtCoder Beginner Contest 118 解题报告
A - B +/- A #include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; b ...
- AtCoder Beginner Contest 120 解题报告
为啥最近都没有arc啊... A - Favorite Sound #include <algorithm> #include <iostream> #include < ...
- AtCoder Beginner Contest 117 解题报告
果然abc都是手速场. 倒序开的qwq. D题因为忘记1e12二进制几位上界爆了一发. A - Entrance Examination 就是除一下就行了... 看样例猜题意系列. #include& ...
- AtCoder Beginner Contest 132 解题报告
前四题都好水.后面两道题好难. C Divide the Problems #include <cstdio> #include <algorithm> using names ...
- AtCoder Beginner Contest 129 解题报告
传送门 写了四个题就跑去打球了.第五题应该能肝出来的. A - Airplane #include <bits/stdc++.h> using namespace std; inline ...
- AtCoder Beginner Contest 127 解题报告
传送门 非常遗憾.当天晚上错过这一场.不过感觉也会掉分的吧.后面两题偏结论题,打了的话应该想不出来. A - Ferris Wheel #include <bits/stdc++.h> u ...
随机推荐
- Python实现字典树
字典树,又称单词查找树,Trie 树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串 ...
- dp --- 二维dp + 最大上升子序列
<传送门> 滑雪 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 74477 Accepted: 27574 ...
- string字符串成员函数
string字符串成员函数 string str1="aaa"; char c='c'; str1.assign("ABCAAAAAAABBBBB");//替换 ...
- 2019-6-28笔记总结-编程语言发展史和python安装
一.编程语言的发展史 1.机器语言(就是010101的二进制数,直接用二进制跟计算机直接沟通交流,直接操作硬件) 优点:计算机能够直接读懂,速度快 缺点:开发效率极低 2.汇编语言(用简单的英文标签来 ...
- C#基础—数组
C#基础之数组 1. 数组的定义与初始化 一维数组: (1) int [] A = new int[4]{ 0,1,2,3}; (2) int[] B ...
- 在Java中如何设置一个定时任务,在每天的一个时间点自动执行一个特定的程序
Quartz定时机制 首先导入jar包到程序内 quartz-all-1.6.0.jar 然后创建一个XML TimeConfig.xml 名字可以自己定义 <?xml version=&quo ...
- 2019 2345网址导航java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.2345网址导航等公司offer,岗位是Java后端开发,因为发展原因最终选择去了2345网址导航,入职一年时 ...
- 【开发工具】- Idea.2018.02注册码激活
1.从下面地址下载一个jar包,名称是 JetbrainsCrack-3.1-release-enc.jar 下载地址: 链接: https://pan.baidu.com/s/1VZjklI3qh ...
- Celery:Daemonization
参考文档:http://docs.celeryproject.org/en/latest/userguide/daemonizing.html#daemonizing
- GitHub Java项目推荐|功能丰富的 Java 工具包|提高开发效率
GitHub Java项目推荐|功能丰富的 Java 工具包|提高开发效率 功能丰富的 Java 工具包.它帮助我们实现了常用的工具方法,从而减少代码的体积,提高开发效率.该项目最初是作者工作项目中的 ...