zoukankan      html  css  js  c++  java
  • USACO 1.3-Combination Lock

    /*
    ID: m1590291
    TASK: combo
    LANG: C++
    */
    #include <iostream>
    #include <fstream>
    #include <math.h>
    /******************************************************************************************************************
                    此题没什么难度,简单遍历即可
                    坑一: bool函数里面 return true的判断条件注意。
                    坑二: 对数进行选择的时候容易习惯性从 0 开始 ,而非从 1开始
    ******************************************************************************************************************/
    using namespace std;
    int N;
    bool fuc(int x,int y)
    {
        if(fabs(x-y) <= 2 || fabs(x-y)>=N-2)    //坑一
            return true;
        return false;
    }
    int main()
    {
        ifstream fin("combo.in");
        ofstream fout("combo.out");
    
        int f[3],m[3];
        while(fin>>N)
        {
            int num=0;
            for(int i = 0;i < 3;i ++)   fin>>f[i];
            for(int i = 0;i < 3;i ++)   fin>>m[i];
    
            for(int i = 1;i <= N;i ++){    //坑二
                for(int j = 1;j <= N;j ++){
                    for(int k = 1;k <= N ;k ++){
                        if((fuc(i,f[0]) && fuc(j,f[1]) && fuc(k,f[2])) || (fuc(i,m[0]) && fuc(j,m[1]) && fuc(k,m[2])))
                            num++;
                    }
                }
            }
            fout<<num<<endl;
        }
        fin.close();
        fout.close();
        return 0;
    }
    


  • 相关阅读:
    mysql perl 抓取update语句
    $/ 改变换行符
    $/ 改变换行符
    java读取jpg图片旋转按比例缩放
    感应器
    lisp分支
    鸡肋的Drools
    postgre去重复记录
    拖拽到指定位置
    base64coder调用
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6352037.html
Copyright © 2011-2022 走看看