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

提出 #117

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 22 additions & 2 deletions src/apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@ int n;
int k;
int A[100000];

int p(int index[],int mid){
int sum = 0;
int a;
for(a=0;a<n;a++){
//切り上げにする
sum = sum + (index[a]+mid-1)/mid;
}
return sum;
}

int main(){
int i, lb, ub;
scanf("%d%d", &n, &k);
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}


lb = 0;
ub = 1000000000;
while(ub - lb > 1){
int mid = (lb + ub)/2;
//ここで評価する
if(p(A, mid) <= k){
ub = mid;
}
else{
lb = mid;
}
}
printf("%d\n",ub);
return 0;
}
15 changes: 12 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@ int main(){
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}



lb = -1;
ub = n;
while(ub - lb > 1){
int mid = (lb + ub)/2;
if(A[mid] >= k){
ub = mid;
}
else{
lb = mid;
}
}
printf("%d\n",ub);
return 0;
}
24 changes: 22 additions & 2 deletions src/spear.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,34 @@ int n;
int k;
int A[100000];

int p(int index[],int mid){
int sum = 0;
int a;
for(a=0;a<n;a++){
//切り捨てで考える
sum = sum + index[a]/mid;
}
return sum;
}

int main(){
int i, lb, ub;
scanf("%d%d", &n, &k);
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}


lb = 0;
ub = 1000000001;
while(ub - lb > 1){
int mid = (lb + ub)/2;
if(p(A, mid) < k){
ub = mid;
}
//k以上になった時に下限を上げて終了条件
else{
lb = mid;
}
}
printf("%d\n",lb);
return 0;
}
43 changes: 41 additions & 2 deletions src/works.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,53 @@ int n;
int k;
int A[100000];

int p(int index[],int mid){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原因は特定してないですが,
多くのケースで正しく動いてないです.
もう一度確認してみてください.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works.c修正しました。
例外処理が足りなかったのと恐らくerrorの回数が複数加算されることでエラーに分岐しなくなっていたのが原因と考えられます。
そのため一回pの中身を書き換えました。

int sum = 0;
//人数のカウント、これとkを比較し評価
int count = 1;
int a;
for(a=0;a<n;a++){
if(mid>=index[a]){
sum=sum+index[a];
//仕事量がmid超えるか確認
if(sum>mid){
//次の人に移る
count=count+1;
//次の仕事を保存
sum=index[a];
}
}
else{
//ありえないパターン
return k+1;
}
}
if(count>k){
return k+1;
}
else{
return count;
}
}

int main(){
int i, lb, ub;
scanf("%d%d", &n, &k);
for(i = 0; i < n; i++){
scanf("%d", &A[i]);
}


lb = 0;
ub = 1000000000;
while(ub - lb > 1){
int mid = (lb + ub)/2;
//ここで評価する
if(p(A, mid) <= k){
ub = mid;
}
else{
lb = mid;
}
}
printf("%d\n",ub);
return 0;
}