题意:有\(n\)个数,首先任选一个正整数\(x\),然后在数组中找到两个和为\(x\)的数,然后去掉这两个数,\(x\)更新为两个数中较大的那个.问你最后时候能把所有数都去掉,如果能,输出最初的\(x\)和每次去除的两个数. 题解:首先现将数组排序,我们每次肯定都是要用数组中当前最大的数和其他数进行组合,这很容易证明,假如我们选两个比它小的数,那么更新后的\(x\)一定永远小于最大值,那么它就永远用不掉,那么第一次的\(x\)一定是数组的最大值和某个数的组合,我们可以枚举来处理,然后剩下的过程…
A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold: The product of all numbers in the…
题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 secondmemory limit per test256 megabytes 问题描述 You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pair…
传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The only difference between easy and hard versions i…
t题目链接:http://codeforces.com/contest/1291/problem/B 思路: 用极端的情况去考虑问题,会变得很简单. 无论是单调递增,单调递减,或者中间高两边低的情况都可以变为三种模型. (1)0,1,2,3,4........n-3,n-2,n-1 (2)n-1,n-2,n-3.....3,2,1,0 (3)0,1,2,3,4,.....n.......4,3,2,1,0 那么,我们只需要查看当前位置是否大于等于极端模型(3)在这个位置的数值,如果当前位置不满足…
You are given an array aa consisting of nn integers. In one move, you can choose two indices 1≤i,j≤n1≤i,j≤n such that i≠ji≠j and set ai:=ajai:=aj . You can perform such moves any number of times (possibly, zero). You can choose different indices in d…
因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<int, int> #defin…
题目 题意: 给你n个数,有两种操作,操作1是把第i个位置的数删去, 操作2 是把 a[ j ]= a[ i ]* a[ j ],把a[ i ]删去 .n-1个操作以后,只剩1个数,要使这个数最大 .要你输出这n-1个步骤. 思路: 结构体储存数和位置, 按值排序,然后分类讨论. 1. 负数个数是奇数,无0  .删除最大的一个负数,别的数正常搞定. 2. 负数个数是奇数,有0  .把最大的一个负数给堆积到最后一个0上,删除最后一个0 . 3. 负数个数是偶数,无0  . 不用删,正常处理. 4.…
题意:有一堆石子,你每次可以选择相邻(就算两堆石子中间有很多空堆也不算)的两堆石子,使得两堆石子的个数同时\(-1\),你在刚开始的时候有一次交换相邻石子的机会,问你最后能否拿走所有石子. 题解:对于第一堆石子和最后一堆石子,它们只能靠第二堆石子和倒数第二堆石子减去才合法,所以我们由第一堆石子不断向右推和最后一堆石子不断向左推,这个过程可以用前缀和\(pre\)与后缀和\(suf\)表示.如果我们当前选择堆\(<i-1,i>\)的话,那么前缀和\(pre[i-2]\)和后缀和\(suf[i+1…
题意:有一个长度为\(n\)并且所有元素和为\(0\)的序列,你可以使\(a_{i}-1\)并且\(a_{j}+1\),如果\(i<j\),那么这步操作就是免费的,否则需要花费一次操作,问最少操作多少次使得所有元素为\(0\). 题解:首先优先考虑不用花费的情况,如果\(a_{i}>0\),\(a_{j}<0\),且\(i<j\),那么我们可以免费的使这两个或一个元素变为\(0\),这里我们可以倒着遍历,记录负数的和,如果遇到正数就抵消,如果不足以抵消正数,那么该位置剩余的正数值就…
题意:给你\(n\)个数字,用\(k\)种颜色给他们涂色,要求每个数字都要涂,每种颜色都要用,相同的数字不能涂一样的颜色. 题解:用结构体读入每个数字和它的位置,然后用桶记录每个数字出现的次数,判断是否合法,然后对数字进行排序,从\([1,k]\)不断循环的去涂颜色,这样的好处是一定能保证相同数字涂的颜色不同,然后再按位置排序输出即可. 代码: struct misaka{ int val; int id; int col; }e[N]; int n,k; map<int,int> mp; i…
任意门: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…
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. Arthur and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/problem/C Description Arthur has bought a beautiful big table into his new flat. When he came home, Arthur noticed that the new table is unstable. In t…
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…
题目链接: 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/719/problem/B B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anatoly lives in the university dorm as many other students do. A…
D. Minimization time limit per test  2 seconds memory limit per test  256 megabytes input  standard input  output  standard output You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n. You…
C. Platforms Jumping There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n+1 (more formally, the river can be represented as a sequence of n+2 cells numbered from 0 to n+1). There are also m wooden platforms o…
链接: https://codeforces.com/contest/1272/problem/A 题意: outputstandard output Three friends are going to meet each other. Initially, the first friend stays at the position x=a, the second friend stays at the position x=b and the third friend stays at t…
题目链接:https://codeforces.com/contest/1417/problem/A 题意 给出一个大小为 $n$ 的数组 $a$,每次操作可以选择两个数,然后将一个数加到另一个数上,要求操作后的数不能大于 $k$,问最多可以操作多少次. 题解 除一个最小值外,给每个数一直加最小值. 证明 操作的本质是留下哪一个数,明显留下较小的数更优. 代码 #include <bits/stdc++.h> using namespace std; int main() { ios::syn…
题目链接:https://codeforces.com/contest/1369/problem/E 题意 Lee 有 $n$ 种不同种类的食物和 $m$ 个朋友,每种食物有 $w_i$ 个,每个朋友喜欢吃两种食物 $x_i, y_i$,如果一个朋友被叫去厨房时一个喜欢吃的食物也没有,他就会吃掉 Lee,否则对还有的他喜欢吃的食物一种吃掉一个,问是否存在一个叫朋友去厨房的顺序保证 Lee 不会被吃掉. 题解 设 $s_i$ 为第 $i$ 种食物共需要多少个,若 $w_i \ge s_i$,则喜欢…
题目链接:https://codeforces.com/contest/1369/problem/C 题意 将 $n$ 个数分给 $k$ 个人,每个人分 $w_i$ 个数($\sum_{i = 1}^{k}w_i = n$),每个人的快乐值为分到数的最小值和最大值之和,计算所有人快乐值之和的最大值. 题解 将 $n$ 个数从小到大排序后从两边加起,利用较大的 $w_i$ 跳过尽可能多的较小值. 代码 #include <bits/stdc++.h> using ll = long long;…
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…
题目: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. 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…