USACO1.3.4 Combination Lock

题目链接:1.3.4

为了防止有重复的数字,我开了个三维数组来标记,爆内存,又用vector标记,爆内存...

不得不感慨这份代码.

/*
ID:wang9621
PROG:combo
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
int n;
bool close(int a,int b)
{
    if(abs(a-b)<=2||abs(a-b)>=(n-2)) return true;
    return false;
}
bool judge(int m1,int m2,int m3,int n1,int n2,int n3)
{
    return close(m1,n1)&&close(m2,n2)&&close(m3,n3);
}
int main()
{
    freopen("combo.in","r",stdin);
    freopen("combo.out","w",stdout);
    scanf("%d",&n);
    int a,b,c;
    int e,f,g;
    cin>>a>>b>>c;
    cin>>e>>f>>g;
    int count = 0;
    for(int i = 1; i<=n; i++)
        for(int j = 1; j<=n; j++)
            for(int k = 1; k<=n; k++)
            if(judge(i,j,k,a,b,c)||
               judge(i,j,k,e,f,g))
               count++;
    printf("%d\n",count);
    return 0;
}

 

转载于:https://www.cnblogs.com/littlepear/p/5678913.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值