题意:有\(n\)个点,\(m\)条边,现在要给这些点赋值,,每次只能赋给某一点的四周(所连边)的最小没出现过的值.如果不能按照所给的数赋值,输出\(-1\),否则输出赋值顺序. 题解:我们用\(pair\)记录最后一行所给的数和位置,不难想,每次肯定是赋最小的数,所以我们对其排序,然后遍历取位置,看这个位置周围能赋的值是否满足条件即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #incl…
题意:有一个正整数\(n\),要求写出所有\(1\)~\(n\)的二进制数,统计相邻的两个二进制同位置上不同数的个数. 题解:打表找规律,不难发现: ​ \(00000\) ​ \(00001\) ​ \(00010\) ​ \(00011\) ​ \(00100\) ​ \(00101\) ​ 当最低位时,每次都变换,由低位向高位,每\(2*i\)次变换一次,直接位运算暴力即可. 代码: #include <iostream> #include <cstdio> #include…
题目链接:A.Johnny and Ancient Computer 题意: 给你两个数a,b.问你可不可以通过左移位运算或者右移位运算使得它们两个相等.可以的话输出操作次数,不可以输出-1 一次操作可以最多左移3次或者右移3次 题解: 首先找寻一下这两个数的二进制形式下最右边那个1在什么位置.然后看一下它们的差距是多少(设为x) 那么就让a,b中小的那个数左移x位.之后判断一下它们两个相等不相等就可以了 代码: 1 #include<stdio.h> 2 #include<algori…
题意:有一长度为\(n\)的数组,求最多的区间和相同的不相交的区间的个数. 题解:我们可以先求一个前缀和,然后第一层循环遍历区间的右端点,第二层循环枚举左端点,用前缀和来\(O(1)\)求出区间和,\(pos\)表示当前区间和为\(cur\)的最右端点,如果我们枚举的左端点\(j\)比\(pos[cur]\)所在的最右端点大,那么我们就能得到区间和为\(cur\)的新区间,并更新状态.上面操作我们贪心得出一定是最优的.之后我们再遍历map,求出次数最多的区间和,然后再枚举所有区间,并且注意区间不…
题目链接:https://codeforces.com/contest/1362/problem/A 题意 有一个正整数 $a$,可选择的操作如下: $a \times 2$ $a \times 4$ $a \times 8$ $a\ /\ 2$,如果 $2$ 整除 $a$ $a\ /\ 4$,如果 $4$ 整除 $a$ $a\ /\ 8$,如果 $8$ 整除 $a$ 问能否由 $a$ 得到正整数 $b$,以及最少的操作次数. 题解 贪心模拟即可. 代码 #include <bits/stdc+…
Problem A https://codeforces.com/contest/1362/problem/A 判断x/y是不是2的k次方, 如果是 k/3 + (k%3)/2 + (k%3%2)即为答案 #include<bits/stdc++.h> using namespace std; #define ll long long ll log2(ll a) { ll count = 0; while (1) { if (a >>= 1) count++; else break…
题目链接:https://codeforces.com/contest/1362/problem/D 题意 有一个 $n$ 点 $m$ 边的图,每个结点有一个从 $1 \sim n$ 的指定数字,每个结点染与它相邻的结点中最小的未染过的正整数,问是否存在某种顺序可以将所有结点染为指定数字,如果存在,输出染色顺序,否则输出 $-1$ . 题解 边数最多为 $5 \times 10^5$ 而不是 $n^2$,所以逐点 $bfs$ 的复杂度最大为 $10^6$,模拟即可. 代码 #include <b…
题目链接:https://codeforces.com/contest/1362/problem/C 题意 计算从 $0$ 到 $n$ 相邻的数二进制下共有多少位不同,考虑二进制下的前导 $0$ .($1≤n≤10^{18}$) 题解 逐位考虑.因为值是连续的,所以从右至左第 $i$ 位的 $01$ 周期为 $2^i$ .计算出完整的 $01$ 周期个数 $t$,每个完整的周期内有一对 $01$ 相邻,相邻的完整周期间共有 $t - 1$ 对 $01$ 相邻,然后考虑多余的周期长度,如果之前有完…
题目链接:https://codeforces.com/contest/1362/problem/B 题意 有一个大小及元素值均不超过 $1024$ 的正整数集合,求最小正整数 $k$,使得集合中的每个元素异或 $k$ 后得到的新集合与原集合相等,若这样的 $k$ 不存在输出 $-1$ . 题解 数据范围较小,枚举即可. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n;…
B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578/problem/B Description You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the number…
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:…
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. A…
任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions…
B. Anton and currency you all know time limit per test 0.5 seconds memory limit per test 256 megabytes input standard input output standard output Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that…
A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performi…
A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial…
C. Hacker, pack your bags!     It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hac…
B. Mislove Has Lost an Array time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts…
E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving…
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最右边的子序列的头部和最左边的子序列的尾部到\(s\)的尾部这两个子串,除去这两个子串,我们要找的最大子串一定在子序列的头部到尾部中,即子序列中两个相邻字符位置的间隔,那么很显然,我们想让相邻的字符之间相隔最大,所以问题也就转化成了:求模式串的相邻字符在主串中的最大间隔长度,最优的情况一定是最左的子序…
题意:有\(n\)个数,每次可以选\(k(1\le k\le n)\)个数,并且得到\(a_1+max(0,a_2-1)+max(0,a_3-2)+...+max(0,a_k-k+1)\)的贡献,问最少选多少次使得总贡献不小于\(m\). 题解:我们从大到小排序,然后二分答案,贪心,如果答案是\(k\)天,那么对于前\(k\)个数,我们一定单独选它们分配到不同的\(k\)个集合中,然后再重复这个过程,从\(k+1\)个数开始循环分配到不同j集合中,这样一定能得到最大的贡献. 代码: ll n,m…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393…
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输出”#Color”,如果只有”G”,”B”,”W”就输出”#Black&White”. #include <cstdio> #include <cstring> using namespace std; const int maxn = 200; const int INF =…
 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256…
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard in…
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his info…
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Victor adores the sets theory. Let us remind you that a set is a group of…
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给出的01序列相等(比较时如果长度不等各自用0补齐) 题解: 1.我的做法是用Trie数来存储,先将所有数用0补齐成长度为18位,然后就是Trie的操作了. 2.官方题解中更好的做法是,直接将每个数的十进制表示中的奇数改成1,偶数改成0,比如12345,然后把它看成二进制数10101,还原成十进制是2…