当前位置:网站首页>Brush questions - Luogu -p1161 turn on the light
Brush questions - Luogu -p1161 turn on the light
2022-07-25 13:47:00 【Song Xiangshang_ UP】
P1161 turn on the light -C Language
1、 subject

2、 The problem solving process
(1) for the first time Overtime #define LIGHT 20000// Maximum value of lamp
result :
Code :
// Luogu P1161 turn on the light
#include <stdio.h>
#define NUM 5000//n<=5000
#define LIGHT 20000// Maximum value of lamp
int main() {
int n;// Conduct n operations
int light[LIGHT] = {
0 };// The initial value is off 0
double a[NUM] = {
0.0 };
int t[NUM] = {
1 };
int k;// You need to press the number of the switch
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++) {
// The number of the lamp is from 1 Start
k = (int)(a[i]*j);// Down to the whole
light[k] = (light[k] == 0) ? 1 : 0;// Switch the state of the lamp
}
}
i = 1;// Start from the first light
while (light[i] == 0) {
// The status of the lamp is off
i++;
}
printf("%d",i);// The status of the light is on
return 0;
}
(2) The second time
result :
Code :
// Luogu P1161 turn on the light
#include <stdio.h>
#define NUM 5000//n<=5000
#define LIGHT 20000// Maximum value of lamp
int main() {
int n;// Conduct n operations
int light[LIGHT] = {
0 };// The initial value is off 0
double a[NUM] = {
0.0 };
int t[NUM] = {
1 };
int k;// You need to press the number of the switch
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++) {
// The number of the lamp is from 1 Start
k = (int)(a[i]*j);// Down to the whole
light[k] = (light[k] == 0) ? 1 : 0;// Switch the state of the lamp
}
}
i = 1;// Start from the first light
while (light[i] == 0) {
// The status of the lamp is off
i++;
}
printf("%d",i);// The status of the light is on
return 0;
}
边栏推荐
- Hcip eighth day experiment
- Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?
- Applet sharing function
- Int array get duplicate data
- LabVIEW的内部错误
- Mxnet implementation of densenet (dense connection network)
- Azure Devops (XIV) use azure's private nuget warehouse
- mujoco_ Py Chinese document
- Canvas judgment content is empty
- Peripheral system calls SAP's webapi interface
猜你喜欢

From input URL to web page display

Introduction and features of numpy (I)

leetcode1 --两数之和

Preparing for the soft test for junior programmers in the second half of 2022

What are the ranking strategies for mobile websites, independent apps and websites?

Introduction to jupyter notebook

Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?

嵌入式代码如何进行重构?

职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?

Leetcode -- addition of four numbers II
随机推荐
0719RHCSA
LabVIEW的内部错误
伯克利博士『机器学习工程』大实话;AI副总裁『2022 ML就业市场』分析;半导体创业公司大列表;大规模视频人脸属性数据集;前沿论文 | ShowMeAI资讯日报
Numpy快速入门
Azure Devops (XIV) use azure's private nuget warehouse
Numpy quick start
Applet starts wechat payment
安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
NoSQL,关系型数据库,行列数据库对比、类比
From input URL to web page display
0710RHCSA
刷题-洛谷-P1089 津津的储蓄计划
0717RHCSA
Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
C # basic learning (XXIII)_ Forms and events
Peripheral system calls SAP's webapi interface
Int array get duplicate data
Preparing for the soft test for junior programmers in the second half of 2022
What problems should SEOER pay attention to when baidu searches and attacks pirated websites?
How can information security engineers prepare for the soft exam in the second half of 2022?