Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to find out someone has changed the volume to aa. Of course, Bob has a remote control that can change the volume. There are six buttons (−5,−2,−1,+1,+2,+5…
Long is a huge fan of CFC (Codeforces Fried Chicken). But the price of CFC is increasing, so he decides to breed the chicken on his own farm. His farm is presented by a rectangle grid with rr rows and cc columns. Some of these cells contain rice, oth…
Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end! The tournament consisted of nn (n≥5n≥5) teams around the world. Before the tournament starts, Bob has…
Hanh lives in a shared apartment. There are nn people (including Hanh) living there, each has a private fridge. nn fridges are secured by several steel chains. Each steel chain connects two different fridges and is protected by a digital lock. The ow…
好吧,其实我拿到这个题的时候,首先想到了bfs,写完之后,开开森森的去交代码,却在第二个数据就TEL,然后优化半天,还是不行. 最终,我盯着1,2,5发呆半天,wc,然后直接贪心 #include<iostream> using namespace std; int main() { int T; cin>>T; while(T--) { int a,b; cin>>a>>b; int x = abs(a - b); ; x %= ; ans += x /…
Codeforces Round #601 (Div. 2) ---- 比赛传送门 周二晚因为身体不适鸽了,补题补题 A // http://codeforces.com/contest/1255/problem/A /* 签到题 简单的贪心题 本考虑过是否有先小于再加上去会更小的情况 但两种情况恰好步数是一样的 */ #include<iostream> #include<cstdio> #include<cmath> using namespace std; int…
传送门 A. Changing Volume 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/19 22:37:33 */ #include <bits/stdc++.h> #define MP make_pair #define fi first #define se second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define…
cf 上的一道好题:  首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是  所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> #include<algorithm> #include<cmath> using namespa…
D. Berland Fair time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output XXI Berland Annual Fair is coming really soon! Traditionally fair consists of nn booths, arranged in a circle. The booths ar…
Codeforces Round #601 (Div. 2) E2. Send Boxes to Alice (Hard Version) N个盒子,每个盒子有a[i]块巧克力,每次操作可以将盒子中的一块巧克力左移或右移,要求移动后的每个盒子中的巧克力数量都能被k整除(无视空盒子),求最小的操作数.(1<=N<=1e6,0<=a[i]<=1e6) 题解 k只需考虑巧克力总数的质因子 考虑每个盒子的贡献,盒子中可以保存k的整数倍(k*i)块巧克力,从左向右递推,每个盒子保留最大数目的…
#include <bits/stdc++.h> using namespace std; typedef long long ll; ; int a[N]; int n; bool prime(int x) {//判断是否为质数 ; i*i <= x; i++) { ) return false; } return true; } ll solve(int x) { vector<int>b; ll ans = ; ; i <= n; i++) { &&…
//为了连贯,采取一条路形式,从第一行开始 也就是s型 #include <bits/stdc++.h> using namespace std; ; char str[MAXN][MAXN]; vector<char> ch;//存放鸡的名字 void init() { '; i++) ch.emplace_back(i); for(char i='A'; i<='Z'; i++) ch.emplace_back(i); for(char i='a'; i<='z';…
把每一次输入的一组数字存下来,然后把每个数字出现的组数存下来 然后找只出现过一次的数字a,那么这个数字a不是开头就是结尾,默认为开头(是哪个都无所谓),然后去找和它出现在同一组的两个数字b和c,而b和c同时出现的只有两组,除了已经知道的,就是需要去查找的,然后循环,同时存在的组数,找到两个数字a和b同时出现的组而且不是第一组,找到之后的组的第三个数字,就是要接在后面的数字,然后循环这个操作 #include <bits/stdc++.h> using namespace std; ][];//…
//题目要求的是每一个点最少要有两条边连接,所以可以先构成一个环.然后再把剩余的最短的边连接起来 #include<iostream> #include<algorithm> using namespace std ; ; int n,m; struct edge { int num; int w; } a[N]; int T; bool cmp(edge a,edge b) { return a.w<b.w; } void solve() { ; ; i<=n; i+…
先分解质因数,对于当前a[i],假设当前的质因数为x,这个位置要满足能被k整除,有两个可能,要么是它向后一个转移x%k个,要么是后一个向它转移k-x%k个. 对于每一个a[i]满足后,因为只会对下一个位置产生影响,所以下一个位置a[i+1]算上a[i]产生的影响,之后又是一个新的子问题(禁止套娃). 对于每一个质因数x,对所有所有位置i求min(a[i],x-a[i])的和,取所有质因子i的求和的最小值作为答案. #define HAVE_STRUCT_TIMESPEC #include<bit…
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; vector<char>ans; ][]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ';++i) ans.emplace_back(i); for(int i='A';i<='Z';++i) ans.emplace_back(i…
C. Recycling Bottles   It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bott…
D. Lazy Student   Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to…
D. Fish Weight 题目连接: http://www.codeforces.com/contest/298/problem/D Description It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number.…
A. Snow Footprints 题目连接: http://www.codeforces.com/contest/298/problem/A Description There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th blo…
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/problem/C Description Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary…
A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Description Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries…
题目:Click here #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; +; int n, m; int main() { while( ~scanf("%d %d", &n, &m ) ) { ) { printf("1\n"); continue; } ) printf( ); else…
题目链接 给你一个n∗m的矩阵res,让你输出一个n∗m的矩阵a,这个矩阵满足:给你一个n*m的矩阵res,让你输出一个n*m的矩阵a,这个矩阵满足:给你一个n∗m的矩阵res,让你输出一个n∗m的矩阵a,这个矩阵满足: ai,j代表第i行第j列的元素,通过减小res之后,使得第i行,第j列的所有元素的最大值a_{i,j}代表第i行第j列的元素,通过减小res之后,使得第i行,第j列的所有元素的最大值ai,j​代表第i行第j列的元素,通过减小res之后,使得第i行,第j列的所有元素的最大值 最小…
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is to…
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The clique problem is one of the most well-known NP-complete problems. Under some simplification it can be formulated as f…
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory limit per test256 megabytes 问题描述 Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange…
任意门:http://codeforces.com/contest/1066/problem/B B. Heaters time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vova's house is an array consisting of nn elements (yeah, this is the first probl…
E. Distributing Parts time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed…
#include<bits/stdc++.h>using namespace std;int order[300007];long long t[300007],ans[300007];int main(){    int n;    long long m; scanf("%d%lld",&n,&m); for(int i=1;i<=n;i++)  scanf("%lld",&t[i]); t[n+1]=2e18; for…