在幼儿园的时候,我们就学习过把一个数分成\(a\)与\(b\),我们只需要用计算机来模拟这个过程就可以了。

我们先从奇数开始看起,以\(5\)为例:

我们可以发现,\(5\)可以分成\(1\)和\(4\),\(2\)和\(3\),\(3\)和\(2\),以及\(4\)和\(1\),也就是说,一个奇数可以有\(n-1\)种方法进行分解,去重后也就是\((n-1)\div2\)种方法。

可以在举一个例子,如\(7\),它可以分成\(1\)和\(6\),\(2\)和\(5\),\(3\)和\(4\),\(4\)和\(3\),\(5\)和\(2\),\(6\)和\(1\),去重后就是\(1\)和\(6\),\(2\)和\(5\),\(3\)和\(4\),共\(3\)种,再用刚刚推出的公式,\((7-1) \div 2 = 3\),发现公式是正确的。

再看偶数,在这里以\(4\)为例。

我们可以发现,一共有\(3\)种方法可以将\(4\)分解,和奇数一样,也有\(n-1\)种方案,其中,\(2\)与\(2\)是重复的,去掉,\(3\)和\(1\)也是重复的,去掉。因此我们发现,\(4\)只有\(1\)和\(3\)一种分解方法,可以用\((n-1)\div2\)的方法判断。

最后我们发现,他们的公式都一样,所以可以直接套公式。

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<(n-1)/2;
return 0;
}

题解 AT5632 【Sum of Two Integers】的更多相关文章

  1. LeetCode Sum of Two Integers

    原题链接在这里:https://leetcode.com/problems/sum-of-two-integers/ 题目: Calculate the sum of two integers a a ...

  2. [LeetCode] Sum of Two Integers 两数之和

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  3. Nim Game,Reverse String,Sum of Two Integers

    下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...

  4. LeetCode 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  5. leetcode371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  6. 【LeetCode】Sum of Two Integers

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  7. 每天一道LeetCode--371. Sum of Two Integers

    alculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Examp ...

  8. 371. Sum of Two Integers -- Avota

    问题描述: Calculate the sum of two integers a and b, but you are not allowed to use the operator + and - ...

  9. Leetcode 371: Sum of Two Integers(使用位运算实现)

    题目是:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. ...

  10. LeetCode 371. Sum of Two Integers (两数之和)

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

随机推荐

  1. ospf路由协议源码学习

    目前,主要有两个版本的源码实现,一是quagga,一是bird. quagga的代码大概有3-4万行,有提到unnumbered interface, bird的代码大概1万行,但没有提到unnumb ...

  2. gitlab(五):一个开发流程实例

    一个多人开发的样例 开发的流程我们都知道: 根据项目版本,创建里程碑,创建开发的issue,分配给dev dev从master clone代码,创建分支就行开发,开发完成之后,提交分支 dev给开发负 ...

  3. ubuntu16.04 自建源

    来自于https://www.cnblogs.com/liangqihui/p/7150066.html APT本地源的搭建(可用于局域网apt-get源搭建或者本地源) 本文档介绍使用apt-mir ...

  4. 杭电-------2041超级楼梯(c语言写)

    /* 当未走的楼梯大于1时,可以选择走一步或者走两步,每次所做的选择相似, 符合分治法的特性,因此选择分治法,又测试用例有多组,为了避免多组 用例的重复计算,可用一个数组将已经知道的剩下的楼梯可以走的 ...

  5. 优雅地使用 C++ 制作表格:tabulate

    作者:HelloGitHub-ChungZH 0x00 介绍 tabulate tabulate 是一个使用 C++ 17 编写的库,它可以制作表格.使用它,把表格对齐.格式化和着色,不在话下!你甚至 ...

  6. docker实战部署Javaweb项目

    一.部署环境说明 docker服务版本:version 18.09.0nginx服务版本:version: nginx/1.15.10redis服务版本:version: redis/5.0.3tom ...

  7. kms在线激活windows和office

    本激活,只适用vol版本的windows系统和office 激活windows在windows中使用管理员方式打开cmd命令输入slmgr /skms chongking.com切换kms服务器地址为 ...

  8. uniapp简易直播

    实验准备 在服务器部署nginx-rtmp作为我们直播推流和拉流的服务器(如果服务商选择七牛,也是直接给地址推流).为了加快部署,我在这一步使用Docker. docker pull tiangolo ...

  9. Cesium动态绘制实体(点、标注、面、线、圆、矩形)

    //自定义绘制图形,支持 点,线,面,矩形,圆,标识,可自定义绘制过程中的和绘制完的预览 this.drawGraphic = function(view,_mode,_callback,_Graph ...

  10. Resnet——深度残差网络(一)

    我们都知道随着神经网络深度的加深,训练过程中会很容易产生误差的积累,从而出现梯度爆炸和梯度消散的问题,这是由于随着网络层数的增多,在网络中反向传播的梯度会随着连乘变得不稳定(特别大或特别小),出现最多 ...