[计蒜客][枚举]北极圈远征 原创
题目来源 计蒜客程序设计竞赛基础课(蓝桥杯省赛)
算法标签 枚举
题目描述

思路
忍不住小学生英语写了一波
//
//x+k x+2k x+3K x+4k x+5k x+6k
//week 7x+21k
//the sum (7x+21k)*52
//we can get an equation : (7x+21k)*52=n
//now we need going to take x and k
//enumerate x,then we can use the equation to get k
//k= (n/52-7x)/21 ,if(n/52-7*x)%21==0 that means the eqation having a solution
//now we geted the x by enumeratation
//we geted the k by the equation
//int x=100;x>=1;x-- we're minimizing k,so we need maximizing x
//(n/52-7*x)/21<=0)continue; K is not a positive integer
//(n/52-7*x)%21!=0 continue; K no solution
AC代码
#include<iostream>
using namespace std;
int sum;
int main()
{
int n;
cin>>n;
sum == n;
for(int x=100;x>=1;x--)
if((n/52-7*x)%21==0&&(n/52-7*x)/21>0){cout<<x<<endl<<(n/52-7*x)/21;return 0;}
}

浙公网安备 33010602011771号