-
Notifications
You must be signed in to change notification settings - Fork 171
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
submit #145
base: main
Are you sure you want to change the base?
submit #145
Changes from all commits
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,18 +1,40 @@ | ||
#include <stdio.h> | ||
#include <stdio.h> //配列の二分探索 | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
int mid=0; //global変数 | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
int i,ub, lb; | ||
scanf("%d%d", &n, &k); | ||
|
||
for(i = 0; i < n; i++){ | ||
scanf("%d", &A[i]); | ||
} | ||
|
||
lb=0,ub=n; | ||
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. 初期値が不適切です. |
||
|
||
if(A[n-1]<k) | ||
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. この条件分岐も資料を参考に無くせます. |
||
{ | ||
mid=n; | ||
} | ||
|
||
|
||
|
||
while(ub - lb > 1) | ||
{ | ||
mid = (ub + lb)/2; | ||
if(A[mid]>k) | ||
{ | ||
ub = mid; | ||
//printf("%d\n",mid); | ||
} | ||
else | ||
{ | ||
lb = mid; | ||
} | ||
//printf("%d\n",mid); | ||
} | ||
printf("%d\n",ub); | ||
//printf("%d,%d",lb,ub); | ||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,71 @@ | |
int n; | ||
int k; | ||
int A[100000]; | ||
int mid=0; //global変数 | ||
int j=0; | ||
int tree_num = 0; | ||
int tmp=0; | ||
|
||
int tree_judge(int m){ | ||
for(j=0;j<n;j++) | ||
{ | ||
if(A[j] >= m) | ||
{ | ||
tree_num += A[j] / m; //切り上げないように | ||
} | ||
} | ||
tmp=tree_num; | ||
tree_num=0; | ||
|
||
//printf("mid=%d,tmp=%d\n",m,tmp); | ||
if(tmp < k) | ||
{ | ||
return 1; | ||
} | ||
else | ||
{ | ||
return 0; | ||
} | ||
//printf("tree_num=%d\n",tree_num); | ||
} | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
|
||
int main(void){ | ||
int i,max,ub,lb,sum_length = 0; | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
|
||
for(i = 0; i < n; i++) | ||
{ | ||
scanf("%d", &A[i]); | ||
sum_length = sum_length + A[i]; | ||
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. 最悪桁あふれします. |
||
//printf("%d\n",A[i]); | ||
|
||
} | ||
|
||
|
||
|
||
ub = sum_length / k; | ||
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 = 0; | ||
|
||
|
||
while(ub - lb > 1) | ||
{ | ||
mid = (ub + lb) / 2; | ||
//printf("mid=%d\n",mid); | ||
if(tree_judge(mid) == 1) | ||
{ | ||
ub = mid; | ||
//printf("lb=%d,ub=%d\n",lb,ub); | ||
} | ||
if(tree_judge(mid) == 0) | ||
{ | ||
lb = mid; | ||
// printf("lb=%d,ub=%d\n",lb,ub); | ||
} | ||
if(k==0) | ||
{ | ||
lb = 0; | ||
} | ||
} | ||
//printf("%d\n",lb); | ||
printf("%d",lb); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コンパイルエラー出てますよ.