Just Another Problem UVA - 11490(枚举)

题意:

你有s个士兵,并打算把他们排成一个r行c列,但有两个"洞"的矩形方队,以迷惑敌人(从远处看,敌人可能误以为一共有r*c个士兵)。洞是两个大小相同的正方形,为了隐蔽性更强,方队边界(即第一行,最后一行,第一列,最后一列)的所有士兵都得在场,且每个洞的四个方向的士兵“士兵”厚度总是相同。输入士兵的实际个数S,计算缺失士兵数的所有可能值

 

解析:

设正方形边长为x  厚度为y

画一下图体会一下  6*y*y + 7*x*y = s

即 y*(6*y+7*x) = s

然后枚举y求x即可

注意y要从1开始枚举。。。

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 100000007
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 10010, INF = 0x7fffffff;

int main()
{
    LL s;
    while(cin>> s && s)
    {
        int ok = 1;
        for(LL i=1; i<=sqrt(s/6 + 0.5); i++)
        {
            if(s % i == 0)
            {
                LL ans = s / i - 6*i;
                if(ans <= 0) continue;
                if(ans % 7) continue;
                ans = ans/7 % MOD;
                ok = 0;
                printf("Possible Missing Soldiers = %lld\n",ans % MOD * ans % MOD * 2 % MOD);
            }
        }
        if(ok) cout<< "No Solution Possible" <<endl;
        cout<<endl;

    }
    return 0;
}

 

posted @ 2018-07-17 19:23  WTSRUVF  阅读(167)  评论(0编辑  收藏  举报