当前位置:网站首页>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;
}
边栏推荐
- How can information security engineers prepare for the soft exam in the second half of 2022?
- I2C can also be powered on by bus!
- GCD details
- 刷题-洛谷-P1151 子数整数
- MySQL 01: Source command
- 刷题-洛谷-P1161 开灯
- Leetcode -- addition of four numbers II
- VIM basic operation summary
- Brush questions - Luogu -p1047 trees outside the school gate
- Leetcode1 -- sum of two numbers
猜你喜欢

刷题-洛谷-P1150 Peter的烟

0715RHCSA
[email protected] (using password:YES)"/>The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)

Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)

LabVIEW的内部错误
![[force deduction] 1030. Arrange matrix cells in distance order](/img/6d/5301be3439cdb35500cbb4ae4a2534.png)
[force deduction] 1030. Arrange matrix cells in distance order
Explain the precision of floating point numbers in detail

The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio

Basic knowledge of binary tree

刷题-洛谷-P1059 明明的随机数
随机推荐
pycharm不能输入中文解决方法
Int array get duplicate data
Brush questions - Luogu -p1046 Tao Tao picking apples
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
C # basic learning (XXIII)_ Forms and events
Leetcode 113. 路径总和 II
Introduction and features of numpy (I)
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
From input URL to web page display
mysql 01: source命令
@classmethod 装饰器
Introduction to jupyter notebook
刷题-洛谷-P1085 不高兴的津津
How to refactor embedded code?
刷题-洛谷-P1151 子数整数
What problems should SEOER pay attention to when baidu searches and attacks pirated websites?
Immortal software in the computer that I don't want to delete all my life
Discussion on principle and application technology of MLIR
stable_ Baselines quick start
0719RHCSA