网易互联网 笔试 <塔> 怎么做?

求ac了塔的讲一下。。还有 这道题是special judge吗?输出方案没要求?#春招##腾讯##简历##网易#
全部评论
一直20%,赛后才想起来可以两座塔合并成一座塔,这点没考虑。。 太菜了。。
点赞 回复 分享
发布于 2018-08-11 17:33
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");         }     } }
点赞 回复 分享
发布于 2018-08-23 22:30
有java代码吗
点赞 回复 分享
发布于 2018-08-12 13:17
//暴力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; }
点赞 回复 分享
发布于 2018-08-11 18:14
我的一个想法是建立最大堆和最小堆,堆内的元素是(i,a[i]),对k个操作改变最大堆和最小堆的极值。不知道这个思路行吗?
点赞 回复 分享
发布于 2018-08-11 18:00
一直20%
点赞 回复 分享
发布于 2018-08-11 17:54
一直20
点赞 回复 分享
发布于 2018-08-11 17:32
同一直20
点赞 回复 分享
发布于 2018-08-11 17:30
这个应该贪心就行吧……但是很迷,我这边一直20%
点赞 回复 分享
发布于 2018-08-11 17:29
mark 最多才20……想到一个思路,等验证看看……
点赞 回复 分享
发布于 2018-08-11 17:28
暴力贪心
点赞 回复 分享
发布于 2018-08-11 17:27
马克,我一直是0%。。。
点赞 回复 分享
发布于 2018-08-11 17:26

相关推荐

06-02 15:17
门头沟学院 Java
心爱的idea:怎么会呢 应该是打招呼有问题 问就说实习6个月全国可飞随时到岗
点赞 评论 收藏
分享
07-17 12:09
门头沟学院 Java
讲的口干舌燥,头都晕了怎么要讲这么长啊
码农索隆:没事,你口干舌燥,他不一定会看,
投递小鹏汽车等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务