全部评论
一直20%,赛后才想起来可以两座塔合并成一座塔,这点没考虑。。 太菜了。。
import java.util.Scanner;
public class xxx {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int MAX = 0,MIN = 10001;
int MAXx = 0 ,MINy = 0;
int k1 = k;
int [][] num = new int[k][2];
int [] nu = new int[n];
for (int i = 0; i < n; i++) {
nu[i] = sc.nextInt();
MIN = MIN>nu[i]?nu[i]:MIN;
MAX = MAX<nu[i]?nu[i]:MAX;
}
if(MAX!=MIN){
while(k1-->0){
for (int i = 0; i < n; i++) {
if(MAX<=nu[i]){
MAX = nu[i];
MAXx = i;
}
if(MIN>=nu[i]){
MIN = nu[i];
MINy = i;
}
}
if(MAX!=MIN){
MIN = --nu[MAXx];
MAX = ++nu[MINy];
num[k-(k1+1)][0] = MAXx+1;
num[k-(k1+1)][1] = MINy+1;
}else{
break;
}
}
MAX = 0;
MIN = 10001;
for (int i = 0; i < n; i++) {
MIN = MIN>nu[i]?nu[i]:MIN;
MAX = MAX<nu[i]?nu[i]:MAX;
}
System.out.println((MAX-MIN)+" "+(k-(k1+1)));
for (int i = 0; i < k; i++) {
System.out.println(num[i][0]+" "+num[i][1]);
}
}else{
System.out.println("0"+" "+"0");
}
}
}
有java代码吗
//暴力AC了
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
while (cin >> n>>m)
{
int cnt = 1;
vector<pair<int, int>> higher;
vector<pair<int, int>> data;
while (n--)
{
int high;
cin >> high;
pair<int,int> hh;
hh.first = high;
hh.second = cnt;
cnt++;
higher.push_back(hh);
}
sort(higher.begin(), higher.end());
int count = 0;
while (m--)
{
if ((higher.front().first == higher.back().first)&&
((higher.front().first+1) == higher.back().first))
break;
pair<int, int> dd;
higher.back().first--;
higher.front().first++;
dd.first = higher.back().second;
dd.second = higher.front().second;
data.push_back(dd);
sort(higher.begin(), higher.end());
count++;
}
cout << higher.back().first - higher.front().first
<< " " << count << endl;
for (auto i : data)
{
cout << i.first << " " << i.second << endl;
}
}
return 0;
}
我的一个想法是建立最大堆和最小堆,堆内的元素是(i,a[i]),对k个操作改变最大堆和最小堆的极值。不知道这个思路行吗?
一直20%
一直20
同一直20
这个应该贪心就行吧……但是很迷,我这边一直20%
mark 最多才20……想到一个思路,等验证看看……
暴力贪心
马克,我一直是0%。。。
相关推荐
点赞 评论 收藏
分享
02-25 16:29
齐鲁工业大学 golang
找工作勤劳小蜜蜂:自我描述部分太差,完全看不出想从事什么行业什么岗位,也看不出想在哪个地区发展,这样 会让HR很犹豫,从而把你简历否决掉。现在企业都很注重员工稳定性和专注性,特别对于热爱本行业的员工。
你实习的工作又太传统的it开发(老旧),这部分公司已经趋于被淘汰,新兴的互联网服务业,比如物流,电商,新传媒,游戏开发和传统的It开发有天然区别。不是说传统It开发不行,而是就业岗位太少,基本趋于饱和,很多老骨头还能坚持,不需要新血液。
工作区域(比如长三角,珠三角,成渝)等也是HR考虑的因素之一,也是要你有个坚定的决心。否则去几天,人跑了,HR会被用人单位骂死。 点赞 评论 收藏
分享
