A. Fafa and his Company(思维题)Codeforces Round #465 (Div. 2)
原题链接:http://codeforces.com/problemset/problem/935/A
题意:有n个员工,从中选取i个领导人,要求每个领导人带的员工是相同的,且领导人带的员工数目不能为0。求选取的方案数
解题思路:我们可以这样思考,最少可以有1个领导人,最多可以有n/2个领导人。那么我们再看看选取的成立条件,我们选完i个领导人之后还剩n-i个员工,如果这些员工能平分给i个领导人,那么就符合条件,所以我们只需要遍历从1到n/2判断可不可行,统计方案数即可。
AC代码:
/*
*邮箱:2825841950@qq.com
*blog:https://blog.csdn.net/hzf0701
*注:代码如有问题请私信我或在评论区留言,谢谢支持。
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<cstring>
#include<map>
#include<iterator>
#include<list>
#include<set>
#include<functional>
#include<memory.h>//低版本G++编译器不支持,若使用这种G++编译器此段应注释掉
#include<iomanip>
#include<vector>
#include<cstring>
#define scd(n) scanf("%d",&n)
#define scf(n) scanf("%f",&n)
#define scc(n) scanf("%c",&n)
#define scs(n) scanf("%s",n)
#define prd(n) printf("%d",n)
#define prf(n) printf("%f",n)
#define prc(n) printf("%c",n)
#define prs(s) printf("%s",n)
#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为代码自定义代码模板***************************************//
int solve(int n){
int cnt=0;
rep(i,1,n/2){
if((n-i)%i==0){
cnt++;
}
}
return cnt;//统计方案数
}
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
ios::sync_with_stdio(false);//打消iostream中输入输出缓存,节省时间。
cin.tie(0); cout.tie(0);//可以通过tie(0)(0表示NULL)来解除cin与cout的绑定,进一步加快执行效率。
int n;
while(cin>>n){
cout<<solve(n)<<endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!