-
Notifications
You must be signed in to change notification settings - Fork 160
提出 #112
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
Riley719
wants to merge
3
commits into
algd2022:main
Choose a base branch
from
Riley719: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
提出 #112
Changes from all commits
Commits
Show all changes
3 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
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
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
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 |
|---|---|---|
|
|
@@ -4,14 +4,52 @@ int n; | |
| int k; | ||
| int A[100000]; | ||
|
|
||
| /* 指定した下限の仕事量xに対し、その仕事量xを超えるまで | ||
| i=0の仕事量から順に足し合わせてゆく。もしある仕事量単体で | ||
| xを超えるならそのxは下限なりえないゆえ0を強制的に返す。 | ||
| そうではないうえで足していった後にもし超えるなら再びカウントを | ||
| 0に戻して同じように足していく。0に戻した瞬間がl回起こったらxを | ||
| 超えないぎりぎりの分け方がl+1個ある、ということになる。このlが | ||
| もしkを超えていたらxの値が小さすぎて細かく分けないと1人当たり仕事量が | ||
| xを簡単に超えてしまうことになるのだから関数は0を返す。k以上ならば | ||
| xの値が十分大きく、細かく分けなくても1人当たり仕事量がxを超えない | ||
| ことになるから関数は1を返す。このようにすると関数の0と1の境目であるxは | ||
| 1人当たり仕事量がxをぎりぎり超えない仕事分配法で、しかも境界右の1は分け方は | ||
| k以下であることになる。もしここでのlが真にkより小さくても適当に | ||
| k個の分担になるようにさらに分割すればよいので、やはいこれが求めるxである。*/ | ||
| int p(int x){ | ||
| int index = 1, quantity = 0, i; | ||
| for(i = 0; i < n; i++){ | ||
| if(x < A[i]){ | ||
| return 0; | ||
| } | ||
| if(x < quantity + A[i]){ | ||
| quantity = 0; | ||
| index = index + 1; | ||
| } | ||
| quantity = quantity + A[i]; | ||
| } | ||
| return index <= k; | ||
| } | ||
|
|
||
| int main(){ | ||
| int i, lb, ub; | ||
|
|
||
| scanf("%d%d", &n, &k); | ||
| for(i = 0; i < n; i++){ | ||
| scanf("%d", &A[i]); | ||
| } | ||
|
|
||
|
|
||
| lb = 0; | ||
| ub = 10000; | ||
|
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. 初期値が不適切です. |
||
| while(ub - lb > 1){ | ||
| int mid = (lb + ub) / 2; | ||
| if(p(mid) == 1){ | ||
| ub = mid; | ||
| } | ||
| else{ | ||
| lb = mid; | ||
| } | ||
| } | ||
| printf("%d\n", ub); | ||
| return 0; | ||
| } | ||
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.
初期値が不適切です.