编程介的小学生 2019-12-31 17:57 采纳率: 0.2%
浏览 51

Everyone Has His Wing Broken 的程序

Problem Description
Long long ago, N gamblers (numbered from 1 to N) got together to gamble. At that time, the kinds of gamble were not that much diversified. The gamble can only be performed in a way that two people played against each other and the one who lost the game would have to give the winner 1.Furthermore,theonewholoseallhismoneyandloseforanothertimewouldgetoutandnevercomeback.Buthestillhastopay1 (He may sell his pants). After playing for quite a long time, they felt as if they had their wings broken, for everyone still here won nothing.
As one of the gamblers, mzry1992 wondered what really happened. Now mzry1992 wants you to tell him what happened between some pairs, for example how much does gambler A win from gambler B directly. But actually you do not know the real situation. So you could just tell him one of the possible situations.

Input
There are T cases and the first line of the input contains the number T. The first line of each case consists of one integer N(2 ≤N≤500), indicating the number of gamblers. Then comes N lines. The i-th line is a non-negative integer smaller than 101 indicating the i-th gambler's initial possess. The next line contains one integer M(0≤M≤10000), indicating the number of pairs of gamblers who gambled. The following M line contains three integer A, B, t(1≤A, B≤N, 1≤t≤100), which means that the gamble A and the gamble B played the game for t times. The final part of each test case begins with an integer Q (1≤Q≤200000). Then Q lines follows. Each line contains two integers A, B. You are asked to answer how much gambler A wins from B.

Output
Output the all the queries from mzry1992.For each test case, your answer should assume that all of the gambles could happen in the one situation. If there is no such situation, just output “Impossible!.

Sample Input
3
3
7
5
9
3
1 2 7
1 3 5
2 3 9
1
1 2

3
1
1
20
1
1 2 2
2
1 2
1 3

3
1
1
20
1
1 2 3
2
1 2
1 3

Sample Output
Case 1:
-5
Case 2:
0
0
Case 3:
Impossible!

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 10:32
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    # 读取数据
    input <- readLines()
    T <- as.integer(input[1])
    data <- data.frame(matrix(NA, nrow = T, ncol = 4))
    
    # 构建赌博记录表
    for (i in 2:T) {
      n <- as.integer(input[i+1])
      data[i, ] <- c(n, as.integer(input[i+2]), as.integer(input[i+3]))
    }
    
    # 求解问题
    query <- readLines()[T+1]
    result <- data.frame()
    
    for (q in query) {
      a, b <- split(q, paste0(' ', q))
      # 获取a和b的下标
      a_idx <- as.numeric(strsplit(a, ' ')[1]) - 1
      b_idx <- as.numeric(strsplit(b, ' ')[1]) - 1
      
      # 计算结果
      result <- rbind(result,
                      data[data$a == a_idx & data$b == b_idx, ])
    }
    
    # 输出结果
    print(result)
    
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上