Skip to content
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

finish #127

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions src/apple.c
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){
TakumiHirose11 marked this conversation as resolved.
Show resolved Hide resolved
int res = 0;
for (int t=0;t<n;t++){
res+=(A[t]+x-1)/x;
}
return res;

Choose a reason for hiding this comment

The 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;
}
27 changes: 22 additions & 5 deletions src/array.c
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;

Choose a reason for hiding this comment

The 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;
}
37 changes: 32 additions & 5 deletions src/spear.c
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;

Choose a reason for hiding this comment

The 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;
}
44 changes: 39 additions & 5 deletions src/works.c
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;
}