-
Notifications
You must be signed in to change notification settings - Fork 167
finish #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
finish #127
Changes from all commits
ba7c763
8f18abc
6806302
ac7c8b2
2aa1e0e
aad21e2
5f1a3ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
|
||
#include <stdio.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
unsigned int check(int x){ | ||
int res = 0; | ||
for (int t=0;t<n;t++){ | ||
res+=(A[t]+x-1)/x; | ||
} | ||
return res; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここはなにか真偽値を返すべきなのでは? |
||
} | ||
|
||
unsigned int binary_search (int lb, int ub, int k){ | ||
while (ub - lb > 1){ | ||
int mid = (lb + ub ) / 2; | ||
if (check(mid)) ub = mid ; | ||
else lb = mid ; | ||
|
||
} | ||
return ub ; | ||
} | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
int i, ub, lb; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
scanf("%d", &A[i]); | ||
} | ||
} | ||
|
||
|
||
lb=0; | ||
ub=1000000000; | ||
|
||
|
||
int res=0; | ||
res = binary_search(lb, ub, k); | ||
printf("%d\n", res); | ||
|
||
|
||
return 0; | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
|
||
#include <stdio.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
unsigned int binary_search (int lb, int ub, int k){ | ||
while (ub - lb > 1){ | ||
int mid = (lb + ub ) / 2; | ||
if (A[ mid ] >= k) ub = mid ; | ||
else lb = mid ; | ||
} | ||
return ub ; | ||
} | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
int i, ub, lb; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
scanf("%d", &A[i]); | ||
} | ||
} | ||
|
||
|
||
lb=-1; | ||
ub=n+1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 初期値が不適切です. |
||
|
||
|
||
int res=0; | ||
res = binary_search(lb, ub, k); | ||
printf("%d\n", res); | ||
|
||
|
||
return 0; | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
|
||
#include <stdio.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
unsigned int number_of_spear(int x){ | ||
int res = 0; | ||
for (int t=0;t<n;t++){ | ||
res+=A[t]/x; | ||
} | ||
return res; | ||
} | ||
|
||
unsigned int binary_search (int lb, int ub, int k){ | ||
while (ub - lb > 1){ | ||
int mid = (lb + ub ) / 2; | ||
if (number_of_spear(mid) >= k) lb = mid ; | ||
else ub = mid ; | ||
} | ||
return lb ; // 少し変更 | ||
} | ||
|
||
|
||
int main(){ | ||
int i, lb, ub; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
int i, ub, lb; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
scanf("%d", &A[i]); | ||
} | ||
} | ||
|
||
|
||
lb=-1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lbの初期値が改善できます.(number_of_spearでゼロ割が起こります.) |
||
ub=1000000001; | ||
|
||
|
||
int res=0; | ||
res = binary_search(lb, ub, k); | ||
printf("%d\n", res); | ||
|
||
|
||
return 0; | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,51 @@ | ||
|
||
#include <stdio.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
int check(int x){ | ||
int tmp=0, count=1; | ||
for(int t=0;t<n;t++){ | ||
tmp+=A[t]; | ||
if(tmp > x){ | ||
t--; | ||
tmp=0; | ||
count++; | ||
} | ||
if(count > k)return 0; | ||
} | ||
return 1; | ||
} | ||
|
||
unsigned int binary_search (int lb, int ub, int k){ | ||
while (ub - lb > 1){ | ||
int mid = (lb + ub ) / 2; | ||
if (check(mid)) ub = mid ; | ||
else lb = mid ; | ||
|
||
} | ||
return ub ; | ||
} | ||
|
||
|
||
int main(){ | ||
int i, lb, ub; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
int i, ub, lb; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
scanf("%d", &A[i]); | ||
} | ||
} | ||
|
||
|
||
lb=0; | ||
ub=1000000000; | ||
|
||
|
||
int res=0; | ||
res = binary_search(lb, ub, k); | ||
printf("%d\n", res); | ||
|
||
|
||
return 0; | ||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.