結果
問題 | No.447 ゆきこーだーの雨と雪 (2) |
ユーザー | HujiLee |
提出日時 | 2016-11-26 11:52:58 |
言語 | Scala(Beta) (3.4.0) |
結果 |
AC
|
実行時間 | 1,594 ms / 2,000 ms |
コード長 | 4,644 bytes |
コンパイル時間 | 10,089 ms |
コンパイル使用メモリ | 280,140 KB |
実行使用メモリ | 77,464 KB |
最終ジャッジ日時 | 2024-06-29 20:37:40 |
合計ジャッジ時間 | 49,190 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 947 ms
63,460 KB |
testcase_01 | AC | 936 ms
63,636 KB |
testcase_02 | AC | 936 ms
63,592 KB |
testcase_03 | AC | 1,235 ms
67,616 KB |
testcase_04 | AC | 1,091 ms
64,472 KB |
testcase_05 | AC | 1,407 ms
69,536 KB |
testcase_06 | AC | 1,464 ms
73,396 KB |
testcase_07 | AC | 1,349 ms
69,508 KB |
testcase_08 | AC | 1,321 ms
69,848 KB |
testcase_09 | AC | 1,455 ms
72,512 KB |
testcase_10 | AC | 1,213 ms
67,836 KB |
testcase_11 | AC | 1,313 ms
68,472 KB |
testcase_12 | AC | 1,332 ms
68,596 KB |
testcase_13 | AC | 1,422 ms
70,396 KB |
testcase_14 | AC | 1,498 ms
72,452 KB |
testcase_15 | AC | 1,359 ms
68,528 KB |
testcase_16 | AC | 1,292 ms
68,852 KB |
testcase_17 | AC | 1,267 ms
67,828 KB |
testcase_18 | AC | 1,030 ms
64,248 KB |
testcase_19 | AC | 1,594 ms
77,464 KB |
testcase_20 | AC | 1,493 ms
72,644 KB |
testcase_21 | AC | 1,317 ms
68,708 KB |
testcase_22 | AC | 1,273 ms
67,824 KB |
testcase_23 | AC | 1,354 ms
68,848 KB |
testcase_24 | AC | 1,404 ms
71,980 KB |
testcase_25 | AC | 1,433 ms
73,400 KB |
testcase_26 | AC | 1,397 ms
69,720 KB |
testcase_27 | AC | 1,377 ms
71,072 KB |
ソースコード
import scala.collection.mutable import scala.io.StdIn /** * Created by Administrator on 2016/11/25 0025. */ class Question($star: Int) { val star = $star private[this] var _countSolved: Int = 0 def countSolved: Int = _countSolved private def countSolved_=(value: Int): Unit = { _countSolved = value } def beSolved: Int = { _countSolved += 1 _countSolved } } class User($name: String) { private var totalScore = -1 private var mapQuesIndex2Score = new mutable.HashMap[Int,Double]() def toString(problems: mutable.HashMap[Int, Question]): String = { def singleQustionCalc(question: Question, solvedOrder: Int): Double = { math.floor(50 * question.star + (50 * question.star) / ((8 + 2 * solvedOrder) / 10.0)) } if (totalScore == -1) { for(i<-problems.keys){ if(mapQuesIndex2SolvedOrder.contains(i)){ mapQuesIndex2Score+=(i->singleQustionCalc(problems(i),mapQuesIndex2SolvedOrder(i))) }else{ mapQuesIndex2Score+=(i->0.0) } } totalScore = { var $ = 0.0 for(i<-mapQuesIndex2Score.keys){ $+=mapQuesIndex2Score(i) } $.toInt } } var result = { var $ = "" for(i<- 0 until mapQuesIndex2Score.size){ if(i>0){ $+=" " } $+=mapQuesIndex2Score(i).toInt } $+=(" "+totalScore) $ } result } def getTotal:Int={ require(totalScore>=0) return totalScore } private var order = 0 val name = $name private var mapQuesIndex2SolvedOrder = new mutable.HashMap[Int, Int]() def setOrder(int: Int): User = { this.order = int this } def getOrder:Int=order def solve(index: Int, solvedOrder: Int): User = { mapQuesIndex2SolvedOrder += (index -> solvedOrder) this } } object Users { /** * 0->Question1{star 1;2 men solved me} */ private var problemsIndex2Question = new mutable.HashMap[Int, Question]() private var users = new mutable.LinkedHashMap[String, User]() private var usersList:List[(String, User)] = null def initStars(ints: Array[Int]): Users.type = { for (i <- ints.indices) { problemsIndex2Question += (i -> new Question(ints(i))) } return this } private def char2Index(chars: String): Int = chars.charAt(0) - 'A' def whoSolvedWhich(name: String, problem: String): Users.type = { val proIndex = char2Index(problem) if (problemsIndex2Question.contains(proIndex)) { problemsIndex2Question(proIndex).beSolved } else { //不可能啊 应该都在 throw new Exception("I'll never show") } if (users.contains(name)) { users(name).solve(proIndex, problemsIndex2Question(proIndex).countSolved) } else { users.+=(name -> new User(name).solve(proIndex, problemsIndex2Question(proIndex).countSolved)) } return this } def setUserOrder(name: String, order: Int): Users.type = { require(users.contains(name), "这个函数必须在whoSolvedWhich后执行") users(name).setOrder(order) return this } def sortUsers: Users.type ={ usersList = users.toList for(i<-usersList){ i._2.toString(problemsIndex2Question) } usersList = usersList.sortWith((a,b)=>{ (a._2.getTotal>b._2.getTotal) match { case true=>true case false=>{ (a._2.getTotal<b._2.getTotal) match { case true=>false case false=>a._2.getOrder<b._2.getOrder } } } }) this } def printAfterSort={ for(i<-usersList.indices){ println(s"${i+1} ${usersList(i)._1} ${usersList(i)._2.toString(problemsIndex2Question)}") } } } /*object UserOrder{ private var map = new mutable.HashMap[String,Int]() def push(username:String): UserOrder.type ={ if(!map.contains(username)){ map+=(username->(map.size+1)) }else{ for(i<-map.keys if map(i) > map(username)){ map(i)-=1 } map(username) = map.size } return this } def getMap: mutable.Map[String, Int] = map }*/ object Main extends App { // val order = UserOrder val users = Users.initStars( { //noinspection ScalaUnusedSymbol val countQuestions = StdIn.readInt() StdIn.readLine().split(" ").map(x => x.toInt) } ) val T = StdIn.readInt() for (i <- 1 to T) { /** * name=username * ques = "ABCD...." */ val Array(name, ques) = StdIn.readLine().split(" ") Users.whoSolvedWhich(name, ques).setUserOrder(name, i) // order.push(name) } users.sortUsers.printAfterSort print("") }