当前位置:网站首页>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;
}
边栏推荐
- Gym installation, invocation and registration
- Immortal software in the computer that I don't want to delete all my life
- Pycharm cannot input Chinese solution
- Applet enterprise red envelope function
- @classmethod 装饰器
- Hcip day 6 notes
- mujoco_py中文文档
- Numpy quick start
- Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
- 0710RHCSA
猜你喜欢

C # basic learning (XXIII)_ Forms and events

IM system - some common problems of message streaming

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

How to refactor embedded code?

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

G027-op-ins-rhel-04 RedHat openstack creates a customized qcow2 format image
![[configure hifive1 revb] the device manager does not recognize the port, and can not connect to j-link via USB](/img/55/a8acdd63a17bf9e3072c9a04babe79.png)
[configure hifive1 revb] the device manager does not recognize the port, and can not connect to j-link via USB

What is your revenue rank among global developers in 2022?

安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
HTTP cache tongtianpian, there may be something you want
随机推荐
职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?
Leetcode -- addition of four numbers II
How happy is the frisbee bureau? 2022 youth trendy Sports Report
uniapp处理后台传输图片
「数字安全」警惕 NFT的七大骗局
刷题-洛谷-P1047 校门外的树
互斥锁、自旋锁、读写锁……理清它们的区别和应用
HTTP cache tongtianpian, there may be something you want
Leetcode202 --- Happy number
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
From input URL to web page display
Nodejs link MySQL error: Er_ NOT_ SUPPORTED_ AUTH_ MODEError: ER_ NOT_ SUPPORTED_ AUTH_ MODE
NoSQL, relational database, row and column database comparison and analogy
[configure hifive1 revb] the device manager does not recognize the port, and can not connect to j-link via USB
[platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1
刷题-洛谷-P1146 硬币翻转
0717RHCSA
leetcode1 --两数之和
Peripheral system calls SAP's webapi interface
@Classmethod decorator