903A. Hungry Student Problem#饥饿的学生(暴力&双层枚举)

题目出处:http://codeforces.com/problemset/problem/903/A

题目大意就是:一个数能否用正整数个另外两个数合成

#include<iostream>
using namespace std;
//双重枚举
int main(){
    int n;cin>>n;
    while(n--){
        int temp;    cin>>temp;    int flag = 1;
        for(int i=0; i<100/3; i++){
            for(int j=0; j<100/7; j++){
                if(i*3+j*7 == temp){ flag = 0; break; }//本来想使用连续break发现不行;
            }
        }
        if(flag) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
    return 0;
}

题目数据比较小,可以考虑直接双层循环,暴力求解。

在做本题的时候有失误,也让自己对break的认识在熟悉了一下,本来天真的认为可双break跳到最外层结束;

但是break第一个执行后,后面的break就会被跳开了。使用break的时候注意其作用空间。(低级错误)

本题优化可以一层枚举中使用取余的方法解决。

时间: 2024-11-09 00:22:00

903A. Hungry Student Problem#饥饿的学生(暴力&双层枚举)的相关文章

uva 10837 - A Research Problem(欧拉函数+暴力)

题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin,要求一个最小的n,欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p?1;如果p和q互质的话有phip?q=phip?phiq 然后根据这样的性质,n=pk11(p1?1)?pk22(p2?1)???pkii(pi?1),将所有的pi处理出来,暴力搜索维护最小值,虽然看上去复杂度非常高,但是因为对于垒乘来说,增长非常快,所以搜索范围大大被缩小了. #include <cs

POJ 1681 Painter&#39;s Problem 【高斯消元 二进制枚举】

任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7667   Accepted: 3624 Description There is a square wall which is made of n*n small square bricks. Some bricks are white while some bric

uva 10837 - A Research Problem(欧拉功能+暴力)

题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin.要求一个最小的n.欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p?1;假设p和q互质的话有phip?q=phip?phiq 然后依据这种性质,n=pk11(p1?1)?pk22(p2?1)???pkii(pi?1),将全部的pi处理出来.暴力搜索维护最小值,尽管看上去复杂度很高,可是由于对于垒乘来说,增长很快,所以搜索范围大大被缩小了. #include <cstdi

Studious Student Problem Analysis

(http://leetcode.com/2011/01/studious-student-problem-analysis.html) You've been given a list of words to study and memorize. Being a diligent student of language and the arts, you've decided to not study them at all and instead make up pointless gam

[示例]创建Student类,输入学生信息并存入字典,将3个存有学生信息的字典存入数组,并计算

代码: main: #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, const char * argv[]) { @autoreleasepool { Student *stu1=[[Student alloc]initWithName:@"wang" andGender:@"male" andAge:@28]; Student *stu

Codeforces Gym 100342C Problem C. Painting Cottages 暴力

Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the sett

玲珑学院OJ 1023 - Magic boy Bi Luo with his excited math problem 树状数组暴力

分析:a^b+2(a&b)=a+b  so->a^(-b)+2(a&(-b))=a-b 然后树状数组分类讨论即可 链接:http://www.ifrog.cc/acm/problem/1023 吐槽:这个题本来是mod(2^40),明显要用快速乘啊,但是用了以后狂T,不用反而过了,不懂出题人 #include <iostream> #include <algorithm> #include <cmath> #include <vector&g

HDU 5402 Travelling Salesman Problem (MUT#9 暴力模拟)

[题目链接]click here~~ [题目大意]:走方格,从[1,1]到[n,m],求中间过程得到的数字和最大,并且输出路径 [思路]: 如果n和m里面有一个是奇数那么全部走遍就好了. 否则要找一个最小的点不要,这个点的坐标要满足x+y是奇数 如果不是的话,舍弃该点一定会导致另外一个点也走不到. 然后找到这个点,暴力输出路径即可. 代码: #include <bits/stdc++.h> using namespace std; const int N=105; typedef long l

Leetcode-552 Student Attendance Record II(学生出勤记录 II)

1 #define maxn 1000000 2 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 3 #define pb push_back 4 #define MOD 1000000007 5 6 class Solution 7 { 8 public: 9 int checkRecord(int n) 10 { 11 long long int dp[2][2][3] {0}; 12 13 dp[0][0][0] = dp[0][0][1