A. Magic Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of…
#include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; int main(){ long long n; cin >>n; while(n){ if(n%10 == 1) n/=10; else if(n%100 == 14 ) n/=100; else if(n%1000 == 144) n/=1000;…
题目传送门 /* 构造:结构体排个序,写的有些啰嗦,主要想用用流,少些了判断条件WA好几次:( */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <vector> #include <map> #include <iostream> #include <string> using name…
A. Magic Numbers 不能出现连续的3个4,以及1.4以外的数字. B. Ping-Pong (Easy Version) 暴力. C. Malek Dance Club 考虑\(x\)二进制每一位1,假设位置为\(p\),则前\(p-1\)位都需要一样,否则之前就计算了贡献,那么后面的位可以任取. D. Psychos in a Line 链表模拟. E. Kalila and Dimna in the Logging Industry 因为\(b_n=0\),所以用最小代价砍倒第…
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/problem/A Description Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the…
D. Magic Breeding link http://codeforces.com/contest/878/problem/D description Nikita and Sasha play a computer game where you have to breed some magical creatures. Initially, they have k creatures numbered from 1 to k. Creatures have n different cha…
A. Magic Spheres   Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he nee…
C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains…
D1. Magic Powder - 1 题目连接: http://www.codeforces.com/contest/670/problem/D1 Description This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single soluti…
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个二进制不断地往右边移一位,每次答案加上这两个的交集,求最后的答案. 题解: 考虑第二个二进制每一位对答案的贡献就行了,然后对第一个二进制算前缀和就ok了. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long l…
链接: https://codeforces.com/contest/1265/problem/B 题意: You are given a permutation p=[p1,p2,-,pn] of integers from 1 to n. Let's call the number m (1≤m≤n) beautiful, if there exists two indices l,r (1≤l≤r≤n), such that the numbers [pl,pl+1,-,pr] is a…
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cstdio> #include<cstring> #include<map> using namespace std; + ; const int INF = 2e9; typedef __int64 LL; int n, k; int x[maxn], y[maxn]; bool…
B. Psychos in a Line Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/319/B Description There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who h…
题目地址:http://codeforces.com/contest/320 第一题:基本题,判断mod 1000,mod 100.,mod 10是不是等于144.14.1,直到为0 代码如下: #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include &…
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The term of this problem is the same as the previous one, the only exception — increased restrictions. Input The first l…
B. Magic Forest time limit per test 1 second memory limit per test 256 megabytes Problem Description Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order n is such a non-degenerate triangle, that lengths of its sides are integers…
题目链接:https://codeforces.com/contest/1417/problem/C 题意 给出一个大小为 $n$ 的数组 $a$,计算当 $k$ 从 $1$ 到 $n$ 取值时在所有 $k$ 长区间中出现的数的最小值. 题解 记录一个值两两间的最大距离,该距离的 $k$ 长区间及之后更长的区间都可能以该值为最小值. Tips 注意两端的处理. 代码一 #include <bits/stdc++.h> using namespace std; int main() { ios:…
题目链接:https://codeforces.com/contest/1265/problem/B 题意 给出大小为 $n$ 的一个排列,问对于每个 $i(1 \le i \le n)$,原排列中是否有一个大小为 $i$ 的连续子排列. 题解 从小到大构造排列,记录当前排列中数的最小下标和最大下标,若最小下标和最大下标的间距刚好为排列的长度,则说明大小为 $i$ 的排列是连续的. 代码一 #include <bits/stdc++.h> using namespace std; void s…
解题思路是: Q=q1^q2.......^qn = p1^p2......^pn^((1%1)^....(1%n))^((2%1)^......(2%n))^.... 故Q的求解过程分成两部分 第一部分是求p1^p2......^pn 第二部分是求((1%1)^....(1%n))^((2%1)^......(2%n))^.... 将其化成矩形的形式 1%1   1%2  ...........  1%n 2%1   2%2  ............ 2%n ................…
题目 比赛的时候找出规律了,但是找的有点慢了,写代码的时候出了问题,也没交对,还掉分了.... 还是先总结一下位移或的性质吧: 1.  交换律 a ^ b = b ^ a 2. 结合律 (a^b) ^ c = a ^ (b^c) 3. 0^a = a; 4. a^a = 0;    a^a^a = a; 5.   知道a,b,c中任意两个就能推知第三个.      a^b = c 两边同时与a异或得: a ^ (a^b) = a^c 即 0^b = a^c  亦即 b = a^c 四个也是一样…
C - Kalila and Dimna in the Logging Industry 很容易能得到状态转移方程 dp[ i ] = min( dp[ j ] + b[ j ] * a[ i ] ), 然后斜率优化一下. 一直以为炸精度了, 忽然发现手贱把while 写成了if .... #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #d…
D. Psychos in a Line time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho…
题意:有一组数,分别用长度从\([1,n]\)的区间去取子数组,要求取到的所有子数组中必须有共同的数,如果满足条件数组共同的数中最小的数,否则输出\(-1\). 题解:我们先从后面确定每两个相同数之间的距离,然后维护每个\(i\)位置上的数到后面所有相同数的最大距离,然后我们就可以dp来搞了,我从\(1\)开始遍历,如果\(a[i]\)后面的所有相同数间隔的最大距离不大于\(k\),那么说明这个数是满足长度为\(i\)的区间的,我们更新状态\(dp[i]=min(a[i],dp[i])\),否则…
题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\). 题解:因为\(a\)不变,而\(b\)每次右移一位,所以我们看\(b\)中\(1\)的位置在\(a\)中所对应的位置,从该位置到最低位,所有为\(1\)的位置都要算一次十进制的数贡献给答案,那么为了降低复杂度,很明显,我们使用前缀和,用十进制记录\(a\)中从低位到高位的和,然后再从低位到高位遍历\(b\),累加所有\(1\)位置在\(a\…
题目链接 题目大意 给定a,b,c,d四个数,其中a<c,b<c,现在让你寻找一对数(x,y),满足一下条件: 1. a<x<c,b<y<d 2. (x*y)%(a*b)==0 题目思路 因为(x*y)%(a*b)==0\(\rightarrow\)x*y\(~\)=\(~\)k*a*b\(~\)=\(~\)k*k1*k2 所以我们要找的就是a,b的因子来保证a%k1\(~\)||\(~\)a%k2\(~\)||\(~\)b%k1\(~\)||\(~\)b%k2为0 而…
题目传送门 /* 题意:n个数字转盘,刚开始每个转盘指向一个数字(0~n-1,逆时针排序),然后每一次转动,奇数的+1,偶数的-1,问多少次使第i个数字转盘指向i-1 构造:先求出使第1个指向0要多少步,按照这个次数之后的能否满足要求 题目读的好累:( */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath>…
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. Angry Students 题目大意:有t队学生,每个学生有两种状态,生气(A)或不生气(P).(话说为什么生气的戴着圣诞帽哇)所有生气的人都会往前一个人丢雪球,被丢到的人也会变得生气,也会丢雪球.问你每队人中最后一个学生变得生气的时刻. 这题就是统计最长的连续的'P'当然前提是左边有生气的人. 代码…
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…
Codeforces Round #346 (Div. 2)---E. New Reform E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city…
Codeforces Round #114 (Div. 2) 代码 Codeforces Round #114 (Div. 2) C. Wizards and Trolleybuses 思路 每条车的到达时间不会小于前一辆车,计算两者时间取最大值. D. Wizards and Huge Prize 思路 \(f(i, j, k)\)表示前\(i\)场比赛赢\(j\)场袋子与奖牌的差值为\(k\)的概率. E. Wizards and Numbers 假设\(a \le b\),那么最后会进入状…