链接:https://ac.nowcoder.com/acm/contest/897/B
来源:牛客网

Trial of Devil
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述

    As an acmer, Devil Aguin particularly loves numbers. This time, with a sequence consisting of n elements 1∼n initially, Devil Aguin asks you to process the sequence until all the elements in it turn to zero. What you can do in one operation are as following :
    1. Select some elements from the sequence arbitrarily.
    2. Select a positive integer x arbitrarily.
    3. Subtract x from the elements you select.

    It is obvious that there are various methods to make elements of the sequence turn to zero. But Devil Aguin demands of you to use the minimum operations. Please tell him how many operations you will use.

输入描述:

    The first line contains an integer number T, the number of test cases.

    ithith of each next T lines contains one integer n(1≤n≤1001≤n≤100), the number of sequence.

输出描述:

For each test case print a number, the minimum number of operations required.
示例1

输入

复制

2
1
2

输出

复制

1
2 题意:
给你一个t组数据,每一个数据给你一个整数n,
代表有一个n的全排列, 你可以做一些操作让他们的值都变成0,。
每次操作,你可以选择全排列中的一些数,然后再选择任意一个x,让那些数减去x。
现在问你最小的操作次数是多少? 思路: 对于每一个整数n的全排列,我们第一次就选择大于等于n/2的那些数,然后减去n/2。
例如8
1 2 3 4 5 6 7 8
8/2=4
减去4后就是
1 2 3 0 1 2 3 4
因为处理1 2 3 4 的时候,就可以顺带的把1 2 3 也给处理了,所以我们问题就转化为了 n/2的全排列的减为0的问题。
通过一直这样转为更小的全排列的操作,我们即可得到最优的解,当n=1的时候,只需要1步就可以减为0。
那么我们递归函数就可以写成:
int f(int x)
{
if(x==)
{
return ;
}else
{
return +f(x/);
}
}

AC代码:

int f(int x)
{
if(x==)
{
return ;
}else
{
return +f(x/);
}
}
int main()
{
//freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout); int t;
gbtb;
cin>>t;
while(t--)
{
int n;
cin>>n;
if(n==)
{
cout<<<<endl;
}else
{
cout<<f(n)<<endl;
}
} return ;
}

2019长安大学ACM校赛网络同步赛 B Trial of Devil (递归)的更多相关文章

  1. 2019长安大学ACM校赛网络同步赛 L XOR (规律,数位DP)

    链接:https://ac.nowcoder.com/acm/contest/897/L 来源:牛客网 XOR 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...

  2. 2019长安大学ACM校赛网络同步赛 J Binary Number(组合数学+贪心)

    链接:https://ac.nowcoder.com/acm/contest/897/J 来源:牛客网 Binary Number 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32 ...

  3. 2019长安大学ACM校赛网络同步赛C LaTale (树上DP)

    链接:https://ac.nowcoder.com/acm/contest/897/C来源:牛客网 LaTale 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 32768K,其他语 ...

  4. 2019长安大学ACM校赛网络同步赛 M LCM (数论)

    链接:https://ac.nowcoder.com/acm/contest/897/M来源:牛客网 LCM 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65 ...

  5. 南昌大学航天杯第二届程序设计竞赛校赛网络同步赛 I

    链接:https://www.nowcoder.com/acm/contest/122/I来源:牛客网 题目描述 小q最近在做一个项目,其中涉及到了一个计时器的使用,但是笨笨的小q却犯难了,他想请你帮 ...

  6. NOI 2018网络同步赛(游记?)

    刚中考完那段时间比较无聊,报名了一个同步赛,报完名才发现成绩单是要挂到网上的,而且因为报的早给了一个很靠前的考号...那布星啊,赶紧学点东西,于是在一周内学了网络流,Treap以及一些数论. Day1 ...

  7. 第十三届北航程序设计竞赛决赛网络同步赛 B题 校赛签到(建树 + 打标记)

    题目链接  校赛签到 对每个操作之间建立关系. 比较正常的是前$3$种操作,若第$i$个操作属于前$3$种,那么就从操作$i-1$向$i$连一条有向边. 比较特殊的是第$4$种操作,若第$i$个操作属 ...

  8. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  9. $NOI$ $2019$ 网络同步赛

    D2T1考试前测了自己造的“假”极限数据,看了看内存发现是118MB,感觉没问题就交上去了. 赛后用Lemon测了一下:MLE 88->0 对于别的题我已经不想再说什么了. update: 由于 ...

随机推荐

  1. express中redirect传递数据

    redirect中无法跟render一样传递数据 在index中,可以通过session重定向到login 在login.js 中获取req.session,渲染到login.ejs中,最后js获取

  2. Using FileUpload

    Using FileUpload FileUpload can be used in a number of different ways, depending upon the requiremen ...

  3. .net sqlite 内存溢出 问题的分析与解决。

    一个小的工具网站,用了sqlite数据库,在并发小的情况一切正常,但是并发量上来之后,就报"out of memory"错误了. 分析了代码,就是很简单的根据一个条件取一段数据,并 ...

  4. AAAI 2019 分析

    AAAI 2019 分析 Google Scholar 订阅 CoKE : Word Sense Induction Using Contextualized Knowledge Embeddings ...

  5. C# WPF 擦出效果,刮图效果

    找了很久 <Window x:Class="TestWebbowser.TestMaskWind" xmlns="http://schemas.microsoft. ...

  6. 十二、RF自定义库(数据库)

    1.自定义第三方库 def DB_select_by_sql(self,db_name,sql): conn=pymysql.connect(db=db_name,user='root',passwo ...

  7. 看看 Delphi XE2 为 VCL 提供的 14 种样式

    看看 Delphi XE2 为 VCL 提供的 14 种样式 其实只提供了 13 个 vsf 样式文件, 还有默认的 Windows 样式, 共 14 种. 在空白窗体上添加 ListBox1 等控件 ...

  8. nginx排查502错误

    排查502错误1.查看/usr/local/nginx/conf/nginx.conf从而知道其错误日志在哪.重点查看其错误日志.2.如果是/tmp/dd.sock2017/05/01 18:48:3 ...

  9. python检测进程是否存在

    import win32com.client def check_exsit(process_name): WMI = win32com.client.GetObject('winmgmts:') p ...

  10. zabbix+grafana使用

    参照文档 https://blog.csdn.net/xiegh2014/article/details/54928883