当前位置:网站首页>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;
}
边栏推荐
- 刷题-洛谷-P1059 明明的随机数
- mujoco_py中文文档
- Serious [main] org.apache.catalina.util.lifecyclebase Handlesubclassexception initialization component
- Error of Tencent cloud [100007] this env is not enable anonymous login
- Hcip eighth day experiment
- 包管理 apt,dpkg
- Pytest.mark.parameterize and mock use
- Applet H5 get mobile number scheme
- The interviewer asked me: how much do you know about MySQL's storage engine?
- Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?
猜你喜欢

leetcode202---快乐数

刷题-洛谷-P1152 欢乐的跳

百度搜索打击盗版网文站点,SEOer应该关注哪些问题?
Explain the precision of floating point numbers in detail

刷题-洛谷-P1085 不高兴的津津

Audio and video technology development weekly | 255

0715RHCSA

C # basic learning (XXIII)_ Forms and events

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output

JS Array indexOf includes sort() 冒号排序 快速排序 去重和随机样本 random
随机推荐
Canvas judgment content is empty
包管理 apt,dpkg
Framework package merge script
Leetcode1 -- sum of two numbers
Canvas判断内容为空
【配置Hifive1-revB】设备管理器中不识别端口,Can not connect to J-Link via USB的解决办法
redis集群的三种方式
leetcode1 --两数之和
Redux usage and analysis
Introduction and features of numpy (I)
刷题-洛谷-P1151 子数整数
HTTP cache tongtianpian, there may be something you want
Peripheral system calls SAP's webapi interface
Blocking queue for concurrent programming
[server data recovery] HP EVA server storage raid information power loss data recovery
stable_baselines快速入门
嵌入式代码如何进行重构?
In order to improve efficiency, there are various problems when using parallelstream
Pytest.mark.parameterize and mock use
【力扣】645.错误的集合