-
Notifications
You must be signed in to change notification settings - Fork 160
提出 #173
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
Open
tetsushi33
wants to merge
4
commits into
algd2022:main
Choose a base branch
from
tetsushi33:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
提出 #173
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,17 +1,43 @@ | ||
| #include <stdio.h> | ||
| /* 8.2 リンゴ狩り */ | ||
| #include<stdio.h> | ||
|
|
||
| #define N 1000000000;//a_iが最大かつn,kが最小の時ubも最大 | ||
| int n; | ||
| int k; | ||
| int A[100000]; | ||
|
|
||
| int p(int x){ | ||
| int i; | ||
| //(A/xの切り上げ の総和)<= k で1、それ以外で0 | ||
| int sum = 0; | ||
| for(i = 0; i < n; i++){ | ||
| sum = sum + ((A[i] + x -1) / x); | ||
| } | ||
| return sum <= k; | ||
| } | ||
|
|
||
| int main(){ | ||
| int i, lb, ub; | ||
| scanf("%d%d", &n, &k); | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
| int i, lb, ub, A_sum = 0;//A_sum:リンゴの総和 | ||
| scanf("%d%d", &n, &k); | ||
|
|
||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| A_sum = A_sum + A[i]; | ||
| } | ||
| lb = A_sum / k;//バッグのサイズは、(リンゴの総和/バッグの数)を下回らない | ||
| ub = N; | ||
|
|
||
| //binary search | ||
| while(ub - lb > 1){ | ||
| int mid = (lb + ub) / 2; | ||
| if(p(mid)){ | ||
| ub = mid; | ||
| }else{ | ||
| lb = mid; | ||
| } | ||
| } | ||
| //answer = ub | ||
| printf("%d\n", ub); | ||
|
|
||
| return 0; | ||
| } | ||
| return 0; | ||
| } | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,18 +1,31 @@ | ||
| /* 8.1 配列の二分探索 */ | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| int n; | ||
| int k; | ||
| int n; //配列の要素数 | ||
| int k; //比較対象 | ||
| int A[100000]; | ||
|
|
||
|
|
||
| int main(){ | ||
| int i, lb, ub; | ||
| scanf("%d%d", &n, &k); | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
|
|
||
| //ub, lb, A[]の設定 | ||
| int i, lb = -1, ub; | ||
| scanf("%d%d\n", &n, &k); | ||
| ub = n; | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
|
|
||
| //binary search | ||
| while(ub - lb > 1){ | ||
| int mid = (lb + ub) / 2; | ||
| if(A[mid] >= k){ | ||
| ub = mid; | ||
| }else{ | ||
| lb = mid; | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| //answer = ub | ||
| printf("%d\n", ub); | ||
| return 0; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,17 +1,41 @@ | ||
| #include <stdio.h> | ||
| /* 8.3 槍作り */ | ||
| #include<stdio.h> | ||
|
|
||
| #define N 1000000000;//槍の長さの最大値は木の長さの最大値 | ||
|
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 n; | ||
| int k; | ||
| int A[100000]; | ||
|
|
||
| int p(int x){ | ||
| int i; | ||
| //A/xの切り捨て の総和がk未満で1 --> 求める値はlbになる | ||
| int sum = 0; | ||
| for(i = 0; i < n; i++){ | ||
| sum = sum + (A[i] / x); | ||
| } | ||
| return sum < k; | ||
| } | ||
|
|
||
| int main(){ | ||
| int i, lb, ub; | ||
| scanf("%d%d", &n, &k); | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
| int i, lb, ub; | ||
| scanf("%d%d", &n, &k); | ||
| lb = 0; | ||
| ub = N; | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
|
|
||
| //binary search | ||
| while(ub - lb > 1){ | ||
| int mid = (lb + ub) / 2; | ||
| if(p(mid)){ | ||
| ub = mid; | ||
| }else{ | ||
| lb = mid; | ||
| } | ||
| } | ||
| //answer = lb(最大値を求める) | ||
| printf("%d\n", lb); | ||
|
|
||
| return 0; | ||
| return 0; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
リンゴの総和 = バッグの数の時など危ないのでは.
3 31 1 1とか.(入力に依存しない初期値でokです.)