QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#49679#2281. BnPCTiceCompile Error//Java117.1kb2022-09-22 12:18:162022-09-22 12:18:19

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-22 12:18:19]
  • 评测
  • [2022-09-22 12:18:16]
  • 提交

answer

import java.io.*;
import java.util.*;
import java.util.Map.Entry;

public class BnPC {
	private static int points;
	private static HashMap<String, Integer> attributePoints = new HashMap<>();
	private static HashMap<String, HashMap<String, Integer>> attributeEventsInfo = new HashMap<>();


	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int total = 0;

		String[] input = in.readLine().split(" ");
		points = Integer.parseInt(input[1]);
		for (int i = 0; i < Integer.parseInt(input[0]); i++) {
			String[] attribute = in.readLine().split(" ");
			attributePoints.put(attribute[0], Integer.parseInt(attribute[1]));
			HashMap<String, Integer> attributeEventInfo = new HashMap<>();
			attributeEventInfo.put("amount", 0);
			attributeEventInfo.put("highest", 0);
			attributeEventInfo.put("amountHighest", 0);
			attributeEventsInfo.put(attribute[0], attributeEventInfo);
		}

		int eventAmount = Integer.parseInt(in.readLine());
		for (int i = 0; i < eventAmount; i++) {
			String[] event = in.readLine().split(" ");
			HashMap<String, Integer> eventMap = attributeEventsInfo.get(event[0]);
			eventMap.put("amount", eventMap.get("amount") + 1);
			int threshold = Integer.parseInt(event[1]);
			if (threshold > attributeEventsInfo.get(event[0]).get("highest")) {
				eventMap.put("highest", threshold);
				eventMap.put("amountHighest", 1);
				if (threshold > attributePoints.get(event[0])) {
					points -= threshold - attributePoints.get(event[0]);
					attributePoints.put(event[0], threshold);
				}
			} else if (threshold == attributeEventsInfo.get(event[0]).get("highest")) {
				eventMap.put("amountHighest", eventMap.get("amountHighest") + 1);
			}
		}

//		for (int i = 0; i < points; i++) {
//			String bestAttr = "";
//			int bestImpact = 0;
//			for (String currentAttr : attributePoints.keySet()) {
//				int amount = attributeEventsInfo.get(currentAttr).get("amount");
//				int amountHighest = attributeEventsInfo.get(currentAttr).get("amountHighest");
//				int score = attributePoints.get(currentAttr) ;
//				if (attributePoints.get(currentAttr) == (attributeEventsInfo.get(currentAttr).get("highest"))) {
//					int impact = score * amountHighest + amount;
//					if (impact > bestImpact) {
//						bestAttr = currentAttr;
//						bestImpact = impact;
//					}
//				} else {
//					if (amount > bestImpact) {
//						bestAttr = currentAttr;
//						bestImpact = amount;
//					}
//				}
//			}
//			attributePoints.put(bestAttr, attributePoints.get(bestAttr) + 1);
//		}





//		int mostOccurring = 0;
//		String mostName = "";
//		int events = attributeEventsInfo.size();
//		ArrayList<String> totalsNames = new ArrayList<>();
//		ArrayList<Integer> totalImpacts = new ArrayList<>();
//		for (Entry<String, HashMap<String, Integer>> entry : attributeEventsInfo.entrySet()) {
//			int amount = entry.getValue().get("amount");
//			int amountHighest = entry.getValue().get("amountHighest");
//			int score = attributePoints.get(entry.getKey());
//			int impact = score * amountHighest + amount;
//			totalsNames.add(entry.getKey());
//			totalImpacts.add(impact);
//			if (amount > mostOccurring) {
//				mostOccurring = amount;
//				mostName = entry.getKey();
//			}
//		}
//
//		List[] sorted = sortTotals(new List[]{totalsNames, totalImpacts});
//		totalsNames = (ArrayList<String>) sorted[0];
//		totalImpacts = (ArrayList<Integer>) sorted[1];
//
//		for (int i = 0; i < totalImpacts.size(); i++) {
//			if (points <= 0) break;
//			if (mostOccurring < totalImpacts.get(i)) {
//				attributePoints.put(totalsNames.get(i), attributePoints.get(totalsNames.get(i)) + 1);
//				points--;
//			} else {
//				attributePoints.put(mostName, attributePoints.get(mostName) + points);
//				points = 0;
//			}
//		}
//
//		attributePoints.put(mostName, attributePoints.get(mostName) + points);



		ArrayList<Attribute> impacts = new ArrayList<>();
		String highestAmountName = "";
		int highestAmount = 0;
		for (String currentAttr : attributePoints.keySet()) {
			int amount = attributeEventsInfo.get(currentAttr).get("amount");
			if (amount > highestAmount) {
				highestAmountName = currentAttr;
				highestAmount = amount;
			}
				int amountHighest = attributeEventsInfo.get(currentAttr).get("amountHighest");
			int score = attributePoints.get(currentAttr);
			int impact = score * amountHighest + amount;
			impacts.add(new Attribute(currentAttr, impact));
		}

		impacts = sortTotals(impacts);

		for (Attribute attribute : impacts) {
			if (points <= 0) break;
			if (highestAmount < attribute.getPoints()) {
				attributePoints.put(attribute.getName(), attributePoints.get(attribute.getName()) + 1);
				points--;
			} else {
				attributePoints.put(highestAmountName, attributePoints.get(highestAmountName) + points);
				points = 0;
			}
		}


		System.out.println(totalPoints());
	}

	private static int totalPoints() {
		int total = 0;
		for (Entry<String, Integer> entry : attributePoints.entrySet()) {
			HashMap<String, Integer> currentAttribute = attributeEventsInfo.get(entry.getKey());
			int attributeScore = entry.getValue();
			if (attributeScore == currentAttribute.get("highest")) {
				total += (currentAttribute.get("amount") - currentAttribute.get("amountHighest")) * attributeScore;
			} else if (attributeScore > currentAttribute.get("highest")) {
				total += currentAttribute.get("amount") * attributeScore;
			}
		}

		return total;
	}

	private static ArrayList<Attribute> sortTotals(List in) {
		ArrayList<Attribute> list = new ArrayList<Attribute>(in);
		if (list.size() <= 1) return list;
		ArrayList<Attribute> firstHalf = (ArrayList<Attribute>) sortTotals(list.subList(0, list.size()/2));
		ArrayList<Attribute> secondHalf = (ArrayList<Attribute>) sortTotals(list.subList(list.size()/2, list.size()));
		ArrayList<Attribute> result = new ArrayList<>();
		int i = 0, n = 0;
		while (i < firstHalf.size() && n < secondHalf.size()) {
			if (firstHalf.get(i).getPoints() > secondHalf.get(i).getPoints()) {
				result.add(new Attribute(firstHalf.get(i).getName(), firstHalf.get(i).getPoints()));
				i++;
			} else {
				result.add(new Attribute(secondHalf.get(n).getName(), secondHalf.get(n).getPoints()));
				n++;
			}
		}
		while (i < firstHalf.size()) {
			result.add(new Attribute(firstHalf.get(i).getName(), firstHalf.get(i).getPoints()));
			i++;
		}
		while (n < secondHalf.size()) {
			result.add(new Attribute(secondHalf.get(n).getName(), secondHalf.get(n).getPoints()));
			n++;
		}
		return result;
	}
}

public class Attribute {
	String name;
	Integer points;

	public Attribute(String name, Integer points) {
		this.name = name;
		this.points = points;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getPoints() {
		return points;
	}

	public void setPoints(Integer points) {
		this.points = points;
	}

	public String toString() {
		return "{name: " + name + "; points: " + points+ ";}";
	}
}

詳細信息

BnPC.java:185: error: class Attribute is public, should be declared in a file named Attribute.java
public class Attribute {
       ^
Note: BnPC.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error