9.12 迅雷笔试编程题

A
题意: 求素勾股个数
思路: 参考.

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <cstdio>
#include <sstream>
#include <cctype>

#define LL long long
#define mst(a, b)   memset(a, b, sizeof(a))
#define pill pait<int, int> 
#define ft first
#define sd second
#define pb push_back
#define mk makr_pair

using namespace std;

const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
int n;
int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt", "r", stdin);
    #endif
    scanf("%d", &n);
    int ans = 0;
    for (int i = 1; 2 * i <= n; ++i) {
        for (int j = i + 1; 2 * i * j <= n; ++j) {
            if (i * i + j * j > n)  break;
            if (gcd(i, j) == 1) {
                if (i % 2 == 0 || j % 2 == 0) {
                    ans++;
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

B
题意: 摆箱子
思路: 二进制枚举所有情况

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <cstdio>
#include <sstream>
#include <cctype>

#define LL long long
#define mst(a, b)   memset(a, b, sizeof(a))
#define pill pait<int, int> 
#define ft first
#define sd second
#define pb push_back
#define mk makr_pair

using namespace std;

const int qq = 1e5 + 10;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;

int main() {
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt", "r", stdin);
    #endif
    int a, b;   scanf("%d%d", &a, &b);
    int n = 17;
    int num[20];
    int ans = -INF;
    for (int i = 0; i < (1 << n); ++i) {
        int maxn = 0;
        for (int j = 0; j < n; ++j) {
            num[j] = (i & (1 << j)) ? b : a;
            maxn += num[j];
        }
        bool f = true;
        int tmp = 0;
        for (int j = 0; j < 6; ++j) {
            tmp += num[j];
        }
        for (int j = 6; j < n; ++j) {
            tmp += num[j];
            if (tmp >= 0)   f = false;
            tmp -= num[j - 6];
        }
        if (f)  ans = max(ans, maxn);
    }
    printf("%d\n", ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值