-
Notifications
You must be signed in to change notification settings - Fork 167
第2回課題提出 #121
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
Closed
Closed
第2回課題提出 #121
Changes from all commits
Commits
Show all changes
6 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,84 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
bool p(int x); | ||
void Num_printing(int i); | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
int main() | ||
{ | ||
int i, lb = 0, ub = 0; | ||
printf("Enter n and k:\n"); | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
printf("Check the value:n=%d, k=%d\n", n, k); | ||
for (i = 0; i < n; ++i) | ||
{ | ||
Num_printing(i + 1); | ||
scanf("%d", &A[i]); | ||
if (ub < A[i]) | ||
{ | ||
ub = A[i]; | ||
} | ||
} | ||
|
||
while (ub - lb > 1) | ||
{ | ||
int mid = (lb + ub) / 2; | ||
// printf("x=%d\n", mid); | ||
if (p(mid)) | ||
{ | ||
// printf("t\n"); | ||
ub = mid; | ||
} | ||
else | ||
{ | ||
// printf("f\n"); | ||
lb = mid; | ||
} | ||
} | ||
|
||
printf("Output Number:%d\n", ub); | ||
return 0; | ||
} | ||
|
||
bool p(int x) | ||
{ | ||
unsigned int count = 0; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
count += (A[i] + x - 1) / x; | ||
// printf("%d\n", count); | ||
} | ||
if (count <= k) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
// 表示をきれいにするためのプログラム | ||
void Num_printing(int i) | ||
{ | ||
if (i % 10 == 1) | ||
{ | ||
printf("Enter the array value(%d st):\n", i); | ||
} | ||
else if (i % 10 == 2) | ||
{ | ||
printf("Enter the array value(%d nd):\n", i); | ||
} | ||
else if (i % 10 == 3) | ||
{ | ||
printf("Enter the array value(%d rd):\n", i); | ||
} | ||
else | ||
{ | ||
printf("Enter the array value(%d th):\n", i); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,84 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
bool p(int x); | ||
void Num_printing(int i); | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
int main() | ||
{ | ||
int i, lb = 0, ub = 0; | ||
// printf("Enter n and k:\n"); | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
// printf("Check the value:n=%d, k=%d\n", n, k); | ||
for (i = 0; i < n; ++i) | ||
{ | ||
//Num_printing(i + 1); | ||
scanf("%d", &A[i]); | ||
if (ub < A[i]) | ||
{ | ||
ub = A[i] + 1; | ||
} | ||
} | ||
|
||
while (ub - lb > 1) | ||
{ | ||
int mid = (lb + ub) / 2; | ||
// printf("x=%d\n", mid); | ||
if (p(mid)) | ||
{ | ||
// printf("t\n"); | ||
lb = mid; | ||
} | ||
else | ||
{ | ||
// printf("f\n"); | ||
ub = mid; | ||
} | ||
} | ||
|
||
printf("%d\n", lb); | ||
return 0; | ||
} | ||
|
||
bool p(int x) | ||
{ | ||
unsigned int count = 0; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
count += A[i] / x; | ||
// printf("%d\n", count); | ||
} | ||
if (count < k) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
// 表示をきれいにするためのプログラム | ||
void Num_printing(int i) | ||
{ | ||
if (i % 10 == 1) | ||
{ | ||
printf("Enter the array value(%d st):\n", i); | ||
} | ||
else if (i % 10 == 2) | ||
{ | ||
printf("Enter the array value(%d nd):\n", i); | ||
} | ||
else if (i % 10 == 3) | ||
{ | ||
printf("Enter the array value(%d rd):\n", i); | ||
} | ||
else | ||
{ | ||
printf("Enter the array value(%d th):\n", i); | ||
} | ||
} |
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,101 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
|
||
int n; | ||
int k; | ||
int A[100000]; | ||
|
||
bool p(int x); | ||
void Num_printing(int i); | ||
|
||
int main(){ | ||
int i, lb, ub; | ||
int main() | ||
{ | ||
int i, lb = 0, ub = 0; | ||
// printf("Enter n and k:\n"); | ||
scanf("%d%d", &n, &k); | ||
for(i = 0; i < n; i++){ | ||
// printf("Check the value:n=%d, k=%d\n", n, k); | ||
for (i = 0; i < n; ++i) | ||
{ | ||
// Num_printing(i + 1); | ||
scanf("%d", &A[i]); | ||
ub += A[i]; | ||
} | ||
|
||
while (ub - lb > 1) | ||
{ | ||
int mid = (lb + ub) / 2; | ||
// printf("x=%d\n", mid); | ||
if (p(mid)) | ||
{ | ||
// printf("t\n"); | ||
ub = mid; | ||
} | ||
else | ||
{ | ||
// printf("f\n"); | ||
lb = mid; | ||
} | ||
} | ||
|
||
printf("%d\n", ub); | ||
return 0; | ||
} | ||
|
||
bool p(int x) | ||
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 temp = 0, i = 0, count = 0; | ||
while (1) | ||
{ | ||
temp = x; | ||
++count; | ||
if (x < A[i]) | ||
{ | ||
// printf("big false\n"); | ||
return false; | ||
} | ||
if (i >= n - 1) | ||
{ | ||
break; | ||
} | ||
while (1) | ||
{ | ||
temp -= A[i]; | ||
// printf("roop1(temp=%d,i=%d,count=%d)\n", temp, i, count); | ||
++i; | ||
if (i >= n || temp < A[i]) | ||
{ | ||
break; | ||
} | ||
} | ||
// printf("roop2(count=%d,i=%d)\n", count, i); | ||
} | ||
if (count > k) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
// 表示をきれいにするためのプログラム | ||
void Num_printing(int i) | ||
{ | ||
if (i % 10 == 1) | ||
{ | ||
printf("Enter the array value(%d st):\n", i); | ||
} | ||
else if (i % 10 == 2) | ||
{ | ||
printf("Enter the array value(%d nd):\n", i); | ||
} | ||
else if (i % 10 == 3) | ||
{ | ||
printf("Enter the array value(%d rd):\n", i); | ||
} | ||
else | ||
{ | ||
printf("Enter the array value(%d th):\n", i); | ||
} | ||
} |
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.
原因までは特定してませんが,多くのケースで正しく動いてないです.
もう一度確認してみてください.
Uh oh!
There was an error while loading. Please reload this page.
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.
了解いたしました。
また、出力の方も了解です。
修正の期限の方は何時迄でしょうか?
Uh oh!
There was an error while loading. Please reload this page.
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.
すぐに書き表せるものとしては
n=k=10
で
a_i
の値が全て1
などですね.(追記:ケースを小さいものに修正しました)後はでたらめなケースのほとんどでかなり大きめの値を出力しています.
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.
修正期限は確認します
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.
修正期限ですが,ちゃんとした日時は未定ですが,
例年では最終課題の締め切りと同じくらいです.
なので,他の課題も考慮しつつ計画的にやっていただければ大丈夫です.