#C++初学记录(acm试题#预处理)
**C - Lucky 7 in the Pocket **
BaoBao loves number 7 but hates number 4, so he refers to an integer as a "lucky integer" if is divisible by 7 but not divisible by 4. For example, 7, 14 and 21 are lucky integers, but 1, 4 and 28 are not.
Today BaoBao has just found an integer in his left pocket. As BaoBao dislikes large integers, he decides to find a lucky integer such that and is as small as possible. Please help BaoBao calculate the value of .
Input
There are multiple test cases. The first line of the input is an integer (about 100), indicating the number of test cases. For each test case:
The first and only line contains an integer (), indicating the integer in BaoBao's left pocket.
Output
For each test case output one line containing one integer, indicating the value of .
Sample Input
4
1
7
20
28
Sample Output
7
7
21
35
正确代码
#include <iostream>
using namespace std;
int a[1000];
int main(){
for (int i = 1; i < 1000; ++i) {
if(i%7==0&&i%4!=0){
a[i]=1;
}
}
int T;
cin>>T;
while (T--){
int n;
cin>>n;
for (int i = n; i < 1000; ++i) {
if(a[i]==1){
cout<<i<<endl;
break;
}
}
}
return 0;
}
题意理解
首先,题意规定了n的取值范围,因为取值范围足够小,仅仅在1-100之间,因此我选择使用预处理即计算1-1000之内所有可以被7整除而不能被4整除的数,接着用for循环进行查找数据得出。
#C++初学记录(acm试题#预处理)的更多相关文章
- #C++初学记录(ACM试题2)
Max Sum Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-seq ...
- #C++初学记录(ACM试题1)
A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...
- #C++初学记录ACM补题(D. Candies!)前缀和运算。
D - Candies! Consider a sequence of digits of length [a1,a2,-,a]. We perform the following operati ...
- #C++初学记录(set进阶#acm cf 190802 B. Subsegments)
B. Subsegments#set进阶 Programmer Sasha has recently begun to study data structures. His coach Stas to ...
- #C++初学记录(sort函数)
sort函数 前言:当进行贪心算法的学习时,需要用到sort函数,因为初学c++汇编语言,sort的具体用法没有深入学习,所以这里进行sort学习记录并只有基础用法并借用贪心算法题目的代码. 百度百科 ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- javaweb初学记录
原文 链接 http://blog.csdn.net/iojust/article/details/52429805 - ---热情依旧 - 环境搭建: - jdk环境配置 jdk下载: http:/ ...
- #C++初学记录(算法4)
A - Serval and Bus It is raining heavily. But this is the first day for Serval, who just became 3 ye ...
- 北大ACM试题分类+部分解题报告链接
转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...
随机推荐
- js两个变量互换值
js两个变量交换值 这个问题看似很基础,但是有很多的实现方式,你知道的有多少呢,网上也有很多的方法,下面就来总结一下 中间变量(临时变量) 临时变量其实很好理解,通过一个中间变量进行交换值 var s ...
- Redis 学习-安装、数据类型与 API 理解、Java 客户端
本博客是在学习<Redis从入门到高可用,分布式实践>教程时的笔记. 同时参考: https://www.cnblogs.com/jiang910/p/10020048.html 一.Re ...
- Python学习日记(七) 文件操作
文件操作: 首先要有一个文件作为对象,例‘文件名’.txt 1.文件路径:例 d:\文件名.txt <1>:绝对路径:从根目录往后的路径 <2>:相对路径:当前目录下的路径有什 ...
- 【English】 Re-pick up English for learning big data (not updated regularly)
2019.10.6 parse:解析mean:平均数stddev:标准偏差 2019.10.7 bigdata platform:大数据平台 2019.10.14 allocate resource ...
- python(字符串函数)
一.字符串函数 1.首字母大小写 capitalize() title() name = "xinfangshuo" print (name.capitalize()) print ...
- 3.kafka 基本配置
1.主题管理 kafka-topics.sh工具脚本用于对主题操作,如创建.删除.修改.分区数.副本数及主题级别的配置. 1.1创建名为kafka-test主题,有2个副本,3个分区 [hadoop@ ...
- MySQL数据库开发规范-EC
最近一段时间一边在线上抓取SQL来优化,一边在整理这个开发规范,尽量减少新的问题SQL进入生产库.今天也是对公司的开发做了一次培训,PPT就不放上来了,里面有十来个生产SQL的案例.因为规范大部分还是 ...
- Luogu P1339 热浪Heat Wave
Luogu P1339 热浪Heat Wave 裸·单源最短路. 但是! 有以下坑点: 算过复杂度发现Floyd跑不过去就不要用了. 如果建边是双向边,边的数组大小要开两倍! 考场上如果再把初始化的$ ...
- 《3+1团队》第九次团队作业:Beta冲刺与验收准备
1.团队项目github仓库地址链接 https://github.com/HaiYou667/3-1Growingfruits 2.Scrum meeting导航: [Beta]Scrum meet ...
- 《逆袭团队》第七次作业:团队项目设计完善&编码
实验十一 团队作业7:团队项目设计完善&编码 内容 项目 软件工程 任课教师博客主页链接 作业链接地址 团队作业7:团队项目设计完善&编码 团队名称 逆袭团队 具体目标 (1)完善团队 ...