链接: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. 误用 Kotlin 中的 sortedWith() 方法排序,集合没有变化

    时间:2019年8月4日14:17:06问题描述:看下边的小例子: data class Man(val name: String, val age: Int, val type: Int) fun ...

  2. mongoose 创建自增字段方法

    first: create counter collection in mongodb:> db.counters.insert({_id:"entityId",seq:0} ...

  3. QPS、TPS、PV、UV、GMV、IP、RPS

    摘自:https://www.citrons.cn/jishu/226.html 关于 QPS.TPS.PV.UV.GMV.IP.RPS 这些词语,看起来好像挺专业.但实际上,我认为是这是每个程序员必 ...

  4. ps - 按进程消耗内存多少排序

    https://www.cnblogs.com/JemBai/archive/2011/06/21/2086184.html https://www.cnblogs.com/jiqing9006/p/ ...

  5. KVM 记录

    mkdir -p /home/hugepagesmount -t hugetlbfs hugetlbfs /home/hugepages 配置文件 vim /etc/libvirt/qemu.conf ...

  6. tensorflow 中图像的读取

    1. 使用gfile读入文件内容.输入的是String,输出3-D tensor.可惜的是输入不能是tensor def decode_jpg(path): r""" 读 ...

  7. python编译报错

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 3:ordi 因为同时安装了python2和python3,所 ...

  8. iOS堆栈内存区别

    堆和栈的区别: · 1> 堆空间的内存是动态分配的,一般存放对象,并且需要手动释放内存. · 2> 栈空间的内存由系统自动分配,一般存放局部变量等,不需要手动管理内存. 接下来我将从以下几 ...

  9. python - from … import …

    from . import XXX        默认的就是在当前程序所在文件夹里__init__.py程序中导入XXX   from .A import XXX     如果当前程序所在文件夹里没有 ...

  10. 基于jquery的bootstrap在线文本编辑器插件Summernote 简单强大

    Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...