VMware笔试第二题有AC的吗

如题,最后剩15分钟写的第二题,调试的时候提示编译错误,看提示信息应该是在algorithm.h的sort函数比较时报的错,求大佬帮忙看看。

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct Node {
	int a, b;
	bool operator <(struct Node n) {
		if (n.b != b)
			return b < n.b;
		return a > n.a;
	}
}Node;

vector<Node> vec;

int main() {
	int n;
	cin >> n;
	vec.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> vec[i].a >> vec[i].b;
	}
	sort(vec.begin(), vec.end());

	int suma = 0, sumb = 0;
	for (int i = 0; i < n; i++) {
		suma += vec[i].a;
		sumb += vec[i].b;
		if (suma >= n-i-1) {
			break;
		}
			
	}
	cout << sumb << endl;

	system("pause");
	return 0;
}


#VMware##笔试题目#
全部评论
第二题过了91,贪心做的,错误情况想到了,但是不知道咋改,省下全AC
点赞 回复 分享
发布于 2019-09-19 09:50
mark求二三题代码
点赞 回复 分享
发布于 2019-09-18 23:30
2. 有n件东西,每件有ai,bi两个属性,从中选出若干件,在满足件数>=n-sigma(ai)的情况下求最小的sigma(bi) 3. 求[a,b]区间内能被k整除但不能被[2,k-1]内任意整数整除的数的个数
点赞 回复 分享
发布于 2019-09-18 22:15
第一题 import java.util.Scanner; public class Test1 {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         int T = scan.nextInt();         for (int i = 0; i < T; i++) {             int n = scan.nextInt(), k = scan.nextInt();             System.out.println(getNum(n, k));         }     }     private static String getNum(int n, int k) {         if (n == 1) return String.valueOf(k - 1);         int num = 0;         StringBuilder sb = new StringBuilder();         if (n % 2 == 0) {             num = (int) Math.pow(10, n / 2 - 1);             num += k - 1;             sb.append(num);             String str = sb.reverse().toString();             sb.reverse().append(str);         } else {             num = (int) Math.pow(10, n / 2);             num += k - 1;             sb.append(num);             String str = sb.reverse().toString();             str = str.substring(1);             sb.reverse().append(new StringBuilder(str));         }         return sb.toString();     } } 第二题 import java.util.*; public class Test2 {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         int T = scan.nextInt();         HashMap<Integer, List<Integer>> map = new HashMap<>();         for (int i = 0; i < T; i++) {             int n = scan.nextInt(), k = scan.nextInt();             List<Integer> list = map.getOrDefault(k, new ArrayList<>());             list.add(n);             map.put(k, list);         }         List<Map.Entry<Integer, List<Integer>>> li = new ArrayList<>(map.entrySet());         Collections.sort(li, new Comparator<Map.Entry<Integer, List<Integer>>>() {             @Override             public int compare(Map.Entry<Integer, List<Integer>> o1, Map.Entry<Integer, List<Integer>> o2) {                 return o1.getKey().compareTo(o2.getKey());             }         });         System.out.println(getNum(li, T));     }     private static int getNum(List<Map.Entry<Integer, List<Integer>>> li, int n) {         int all = 0, res = n, result = 0;         for (int i = 0; i < li.size(); i++) {             List<Integer> list = li.get(i).getValue();             Collections.sort(list, new Comparator<Integer>() {                 @Override                 public int compare(Integer o1, Integer o2) {                     return o2.compareTo(o1);                 }             });             for (int j = 0; j < list.size(); j++) {                 all += list.get(j);                 res--;                 result += li.get(i).getKey();                 if (all >= res)                     return result;             }         }         return result;     } } 第三题 import java.util.Scanner; public class Test3 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); String str = scan.nextLine(); str = str.substring(1, str.length() - 1); String[] strs = str.split(","); int[] array = new int[strs.length]; for (int i = 0; i < strs.length; i++) array[i] = Integer.parseInt(strs[i].trim()); System.out.println(maxSum(array)); } private static int maxSum(int[] array) { if (array.length == 0) return 0; int val = array[0], max = array[0]; for (int i = 1; i < array.length; i++) { if (val > 0) val += array[i]; else val = array[i]; if (max < val) max = val; } return max; } }
点赞 回复 分享
发布于 2019-09-18 21:59
求第二道的解法。。 第三道AC代码也求
点赞 回复 分享
发布于 2019-09-18 21:47
第三题不知道为啥只过了55
点赞 回复 分享
发布于 2019-09-18 21:19
第一题咋做?
点赞 回复 分享
发布于 2019-09-18 21:17
贪心能解吗😂
点赞 回复 分享
发布于 2019-09-18 21:12

相关推荐

喜欢喜欢喜欢:这是我见过最长最臭的简历
点赞 评论 收藏
分享
评论
1
8
分享

创作者周榜

更多
牛客网
牛客企业服务