zoukankan      html  css  js  c++  java
  • 【Codeforces 348A】Mafia

    【链接】 我是链接,点我呀:)
    【题意】

    每轮游戏都要有一个人当裁判,其余n-1个人当玩家 给出每个人想当玩家的次数ai 请你求出所需要最少的玩游戏的轮数 使得每个人都能满足他们当玩家的要求.

    【题解】

    ```cpp /* * 如果有x轮的话 * 理论上每个人都能玩x次 * 但是必须有x人当supervisor * x次的话,每个人能当supervisor的次数为x-a[i] * n*x-∑a[i]就是所有人除去必须的能打supervisor的次数 * 如果n*x-∑a[i] >= x 那么就ok * (n-1)*x-∑a[i]>=0就好 *x>=∑a[i] / (n-1) *要注意x需要大于等于max{a[i]} */ ```

    【代码】

    import java.io.*;
    import java.util.*;
    
    public class Main {
        
        
        static InputReader in;
        static PrintWriter out;
            
        public static void main(String[] args) throws IOException{
            //InputStream ins = new FileInputStream("E:\rush.txt");
            InputStream ins = System.in;
            in = new InputReader(ins);
            out = new PrintWriter(System.out);
            //code start from here
            new Task().solve(in, out);
            out.close();
        }
        
        static int N = 100000;
        static class Task{
            /*
             * 如果有x轮的话
             * 理论上每个人都能玩x次
             * 但是必须有x人当supervisor
             * x次的话,每个人能当supervisor的次数为x-a[i]
             * n*x-∑a[i]就是所有人除去必须的能打supervisor的次数
             * 如果n*x-∑a[i] >= x 那么就ok
             * (n-1)*x-∑a[i]>=0就好
             *x>=∑a[i] / (n-1)
             */
        	int n;
        	int a[];
            
            public void solve(InputReader in,PrintWriter out) {
            	n = in.nextInt();
            	a = new int[N+10];
            	int ma = 0;
            	for (int i = 1;i <= n;i++) {
            		a[i] = in.nextInt();
            		ma = Math.max(ma,a[i]);
            	}
            	long ans;
            	long sum = 0;
            	for (int i = 1;i <= n;i++) sum += a[i];
    	        	if (sum%(n-1)==0) {
    	        		ans = sum/(n-1);
    	        	}else {
    	        		ans = sum/(n-1) + 1;
    	        	}
    	        ans = Math.max(ans, ma);
    	        out.println(ans);
            }
        }
    
        
    
        static class InputReader{
            public BufferedReader br;
            public StringTokenizer tokenizer;
            
            public InputReader(InputStream ins) {
                br = new BufferedReader(new InputStreamReader(ins));
                tokenizer = null;
            }
            
            public String next(){
                while (tokenizer==null || !tokenizer.hasMoreTokens()) {
                    try {
                    tokenizer = new StringTokenizer(br.readLine());
                    }catch(IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                return tokenizer.nextToken();
            }
            
            public int nextInt() {
                return Integer.parseInt(next());
            }
        }
    }
    
  • 相关阅读:
    LeetCode Subsets II
    LeetCode Rotate Image
    LeetCode Palidrome Number
    LeetCode Generate Parentheses
    LeetCode Maximum Subarray
    LeetCode Set Matrix Zeroes
    LeetCode Remove Nth Node From End of List
    Linux Loop设备 使用
    Linux 文件系统大小调整
    LeetCode N-Queens II
  • 原文地址:https://www.cnblogs.com/AWCXV/p/10424271.html
Copyright © 2011-2022 走看看