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 = ;
for(int i=; i</; i++){
for(int j=; j</; j++){
if(i*+j* == temp){ flag = ; break; }//本来想使用连续break发现不行;
}
}
if(flag) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return ;
}
题目数据比较小,可以考虑直接双层循环,暴力求解。
在做本题的时候有失误,也让自己对break的认识在熟悉了一下,本来天真的认为可双break跳到最外层结束;
但是break第一个执行后,后面的break就会被跳开了。使用break的时候注意其作用空间。(低级错误)
本题优化可以一层枚举中使用取余的方法解决。
903A. Hungry Student Problem#饥饿的学生(暴力&双层枚举)的更多相关文章
- Educational Codeforces Round 34 A. Hungry Student Problem【枚举】
A. Hungry Student Problem time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法
Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...
- uva 10837 - A Research Problem(欧拉功能+暴力)
题目链接:uva 10837 - A Research Problem 题目大意:给定一个phin.要求一个最小的n.欧拉函数n等于phin 解题思路:欧拉函数性质有,p为素数的话有phip=p−1; ...
- [LeetCode] Student Attendance Record I 学生出勤记录之一
You are given a string representing an attendance record for a student. The record only contains the ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...
- [示例]创建Student类,输入学生信息并存入字典,将3个存有学生信息的字典存入数组,并计算
代码: main: #import <Foundation/Foundation.h> #import "Student.h" int main(int argc, c ...
- Problem 1014 xxx游戏 暴力+拓扑排序
题目链接: 题目 Problem 1014 xxx游戏 Time Limit: 1000 mSec Memory Limit : 32768 KB 问题描述 小M最近很喜欢玩XXX游戏.这个游戏很简单 ...
- Codeforces Gym 100342C Problem C. Painting Cottages 暴力
Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1 ...
随机推荐
- java内存模型(线程,volatile关键字和sychronized关键字)
volatile关键字 用在多线程,同步变量. 线程为了提高效率,将某成员变量(如A)拷贝了一份(如B),线程中对A的访问其实访问的是B.只在某些动作时才进行A和B的同步.因此存在A和B不一致的情况. ...
- jdk8安装
==安装jdk1.8== [root@ycj ~]# mkdir -p /usr/local/src/jdk //创建目录 [root@ycj jdk]# cd /usr/local/src/jdk ...
- MySQL的异常问题
异常问题
- C++中获取当前时间并格式化输出
#include <string> #include <time.h> using namespace std; string getTime() { time_t timep ...
- codeforces 596 C. p-binary
题意:给你一个n和一个p,让你用 (2k+p)进制来表示n,找出用最少的(2k+p)来表示n. 分析:首先我们看到2k,首先下想到二进制,我们可以我们列出式子,也就是 (2x1 + p)+(2x2 + ...
- 两个exe共享内存数据
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- 小程序使用wxs 解决wxml保留2位小数问题
1.出现溢出表现 从图中可以看到数字超出了很长长度.代码里面是如下这样的.为什么在0.35出现?或者一些相成的计算出现? 而 0.34却不会. 0.41 也会出现,好像是二进制运算出现结果. data ...
- 纯CSS导航栏下划线跟随效果
参考文章 <ul> <li>111</li> <li>2222</li> <li>3333333</li> < ...
- F5 BIG-IPLTM但比组网的三种连接模式(转)
原文链接:https://www.cnblogs.com/yujianadu/p/11850977.html作者:遇见阿杜
- TCP连接为什么三次握手四次挥手
前几天面试某电商被问住了,问的很细,我就说了说连接过程,必然凉凉.在csdn上找了一篇很详细的博客.https://blog.csdn.net/hyg0811/article/details/1023 ...