用户调度问题
标题:用户调度问题 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
在通信系统中,一个常见的问题是对用户进行不同策略的调度,会得到不同的系统消耗和性能。
//package com.yang.Test; import java.util.Scanner; /** * 3 * 15 8 17 * 12 20 9 * 11 7 5 */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int num = scanner.nextInt(); int ans = 0, a, b, c, test = 0; for (int i = 0; i < num; i++) { a = scanner.nextInt(); b = scanner.nextInt(); c = scanner.nextInt(); int min = 0; switch (test) { case 1: min = min(b, b, c); if (min == c) test = 3; if (min == b) test = 2; break; case 2: min = min(a,a,c); if (min == c) test = 3; if (min == a) test = 1; break; case 3: min = min(a,b,b); if (min == b) test = 2; if (min == a) test = 1; break; case 0: min = min(a, b, c); if (min == c) test = 3; if (min == b) test = 2; if (min == a) test = 1; break; } ans+=min; } System.out.println(ans); } private static int min(int a,int b, int c){ if (c <= a && c <= b){ return c; } return Math.min(b,a); }}
n = int(input()) cost = [] for i in range(n): cost.append(list(map(int,input().split()))) dps = 0 last = -1 for i in range(n): if last != -1: cost[i][last] = float('inf') cur = min(cost[i]) dps += cur for j in range(3): if cost[i][j] == cur: last = j print(dps)
#include<iostream> #include<vector> using namespace std; int main() { int n; cin>>n; vector<vector<int>> grid(n, vector<int>(3)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin>>grid[i][j]; } } int sum = 0; int last = -1; for (int i = 0; i < n; i++) { int m = 1000000000; int y = -1; for (int j = 0; j < 3; j++) { if (j != last) { if (grid[i][j] <= m) { m = grid[i][j]; y = j; } } } sum += m; last = y; } cout<<sum<<endl; return 0; }//manfen