forked from opencodeiiita/CodeDigger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencodeiiita#91 from kenma-w/main
created problem
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Solution: | ||
Every Second the count of ON bulbs increses by 1. | ||
If either of the first or last bulb turns ON then it takes 2 seconds for the count to increase. | ||
The maximum number of bulbs which will be ON is equal to ceil(n/2). | ||
So the final answer can be calculated as shown in solution.cpp. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
#define int long long int | ||
|
||
|
||
void solve(){ | ||
int n,x; | ||
cin>>n>>x; | ||
int ans=0; | ||
ans+=min(x-1,n-x); | ||
ans+=(ceil(n*1.0/2)-ans-1)*2; | ||
cout<<ans<<endl; | ||
} | ||
|
||
signed main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int t; | ||
cin>>t; | ||
while(t--){ | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Fix the Bulb | ||
|
||
There are n bulbs, numbered from 1 to n. The Bulbs are malfunctioning(OFF initially).Initially at 0th second the bulb x is in ON state. Every second, the Bulb k | ||
which is in ON state turns OFF and the Bulbs, k−1 | ||
(if it exists) and k+1 (if it exists) turns ON. | ||
|
||
This process happens for all the Bulbs which are in ON state at the same time. | ||
Your task is to determine the least second at which maximum number of Bulbs are turned ON. | ||
|
||
Input | ||
The first line contains the number of test cases t (1≤t≤10000) | ||
The one and only line of each test case contains two integers n and x (1≤n≤10^18;1≤x≤n) | ||
— the number of Bulbs and the Bulb which is ON initially. | ||
Output | ||
output a single integer: the least second at which maximum number of Bulbs are turned ON. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
3 | ||
2 1 | ||
10 8 | ||
67 24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0 | ||
6 | ||
43 |