当前位置:网站首页>刷题-洛谷-P1161 开灯
刷题-洛谷-P1161 开灯
2022-07-25 13:32:00 【宋向上_UP】
P1161 开灯-C语言
1、题目

2、解题过程
(1)第一次 超时 #define LIGHT 20000//灯的最大值
结果:
代码:
//洛谷 P1161 开灯
#include <stdio.h>
#define NUM 5000//n<=5000
#define LIGHT 20000//灯的最大值
int main() {
int n;//进行n次操作
int light[LIGHT] = {
0 };//初始值为关0
double a[NUM] = {
0.0 };
int t[NUM] = {
1 };
int k;//需要按开关的编号
int i,j;
scanf_s("%d", &n);
for (i = 0; i < n; i++) {
scanf_s("%lf %d", &a[i], &t[i]);
for (j = 1; j <= t[i]; j++) {
//灯的编号从1开始
k = (int)(a[i]*j);//向下求整
light[k] = (light[k] == 0) ? 1 : 0;//切换灯的状态
}
}
i = 1;//从第一盏灯开始遍历
while (light[i] == 0) {
//灯的状态为关
i++;
}
printf("%d",i);//灯的状态为开的编号
return 0;
}
(2)第二次
结果:
代码:
//洛谷 P1161 开灯
#include <stdio.h>
#define NUM 5000//n<=5000
#define LIGHT 20000//灯的最大值
int main() {
int n;//进行n次操作
int light[LIGHT] = {
0 };//初始值为关0
double a[NUM] = {
0.0 };
int t[NUM] = {
1 };
int k;//需要按开关的编号
int i,j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%lf %d", &a[i], &t[i]);
for (j = 1; j <= t[i]; j++) {
//灯的编号从1开始
k = (int)(a[i]*j);//向下求整
light[k] = (light[k] == 0) ? 1 : 0;//切换灯的状态
}
}
i = 1;//从第一盏灯开始遍历
while (light[i] == 0) {
//灯的状态为关
i++;
}
printf("%d",i);//灯的状态为开的编号
return 0;
}
边栏推荐
- 嵌入式代码如何进行重构?
- 一味地做大元宇宙的规模,已经背离了元宇宙本该有的发展逻辑
- mysql函数汇总之日期和时间函数
- 业务可视化-让你的流程图'Run'起来(3.分支选择&跨语言分布式运行节点)
- Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
- Pytorch creates its own dataset and loads the dataset
- IM系统-消息流化一些常见问题
- 【服务器数据恢复】HP EVA服务器存储RAID信息断电丢失的数据恢复
- [six articles talk about scalablegnn] around www 2022 best paper PASCA
- R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
猜你喜欢

In order to improve efficiency, there are various problems when using parallelstream

【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)

0713RHCSA

Uncaught SyntaxError: Octal literals are not allowed in strict mode.

Immortal software in the computer that I don't want to delete all my life

JS Array indexOf includes sort() 冒号排序 快速排序 去重和随机样本 random

并发编程 — 内存模型 JMM

【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)

mysql函数汇总之日期和时间函数

机器学习强基计划0-4:通俗理解奥卡姆剃刀与没有免费午餐定理
随机推荐
【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)
arm架构移植alsa-lib和alsa-utils一路畅通
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
全网最简单解决方式1045-Access denied for user [email protected](using password:YES)
MLIR原理与应用技术杂谈
剑指offer专项突击版第10天
说说对hashcode和equals方法的理解?
Jupyter Notebook介绍
Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
hcip第七天笔记
[six articles talk about scalablegnn] around www 2022 best paper PASCA
Excel record macro
HTTP cache tongtianpian, there may be something you want
并发编程之阻塞队列
hcip第八天实验
Excel import and export source code analysis
Blindly expanding the scale of the meta universe has deviated from the development logic of the meta universe
【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
hcip第九天笔记