zoukankan      html  css  js  c++  java
  • Just Another Problem UVA

    题意:

    你有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
    ",ans % MOD * ans % MOD * 2 % MOD);
                }
            }
            if(ok) cout<< "No Solution Possible" <<endl;
            cout<<endl;
    
        }
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    【转】Testing, Thought, and Observations
    【转】Yet another software testing pyramid
    【转】Automated Testing and the Test Pyramid
    Environment setting up troubleshoot.
    [转] Spring相关
    流水账
    Abbreviation
    chrome中文本框样式问题
    Intellij IDEA 使用总结
    限制
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9325399.html
Copyright © 2011-2022 走看看