zoukankan      html  css  js  c++  java
  • CF A. Phoenix and Balance Codeforces Round #638 (Div. 2) 5月1号

    A. Phoenix and Balance
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Phoenix has nn coins with weights 21,22,,2n21,22,…,2n. He knows that nn is even.

    He wants to split the coins into two piles such that each pile has exactly n2n2 coins and the difference of weights between the two piles is minimized. Formally, let aa denote the sum of weights in the first pile, and bb denote the sum of weights in the second pile. Help Phoenix minimize |ab||a−b|, the absolute value of aba−b.

    Input

    The input consists of multiple test cases. The first line contains an integer tt (1t1001≤t≤100) — the number of test cases.

    The first line of each test case contains an integer nn (2n302≤n≤30; nn is even) — the number of coins that Phoenix has.

    Output

    For each test case, output one integer — the minimum possible difference of weights between the two piles.

    Example
    input
    Copy
    2
    2
    4
    
    output
    Copy
    2
    6
    
    Note

    In the first test case, Phoenix has two coins with weights 22 and 44. No matter how he divides the coins, the difference will be 42=24−2=2.

    In the second test case, Phoenix has four coins of weight 22, 44, 88, and 1616. It is optimal for Phoenix to place coins with weights 22 and 1616 in one pile, and coins with weights 44 and 88 in another pile. The difference is (2+16)(4+8)=6(2+16)−(4+8)=6.

    这题的意思就是,他有n个硬币(n是偶数)然后放在两个盘子里然后求相减最小;所以很自然的我们可以想到先放前n/2-1个在一个盘子再把最后一个放进去,因为成指数增加,所以这个盘子肯定重;

     1 #include <bits/stdc++.h>
     2 const int maxn=1e5+50;
     3 const int INF=0x3f3f3f3f;
     4 using namespace std;
     5 int main(){
     6     int t;
     7     cin>>t;
     8     while(t--){
     9         int n;
    10         cin>>n;
    11        double ans=pow(2.0, n*1.0/2);//求前n项和化简得到的公式为ans=2*(2^(n/2)-1)
    12        ans=(ans-1)*2;
    13        cout<<ans<<'
    ';    
    14     } 
    15 
    16 
    17 return 0;
    18 }

    May I love u;

    五月快乐

  • 相关阅读:
    AVL自平衡二叉树
    笔试+面试信息整理----面向笔试学习、面向面经编程
    传入值参数&传入引用参数的区别
    NLPIR智能挖掘实现行业大数据应用价值
    NLPIR大数据挖掘融合库、智、理三大先进理论技术
    NLPIR智能语义挖掘文本大数据深层意义
    NLPIR智能语义技术从采集到分析一步到位
    灵玖软件:NLPIR智能挖掘对文本数据精细化分析
    九眼合同智能审核系统运用NLPIR大数据技术进行核查
    NLPIR九眼智能审核平台助合同文本深度核查
  • 原文地址:https://www.cnblogs.com/ahijing/p/12816793.html
Copyright © 2011-2022 走看看