Skip to content

第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
wants to merge 6 commits into from
Closed
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
73 changes: 70 additions & 3 deletions src/apple.c
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);
}
}
49 changes: 46 additions & 3 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,58 @@ int n;
int k;
int A[100000];

void Num_printing(int i);

int main(){
int main()
{
int i, lb, ub;
scanf("%d%d", &n, &k);
for(i = 0; i < n; i++){
printf("Enter n and k:\n");
scanf("%d %d", &n, &k);
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]);
}

lb = -1;
ub = n;

while (ub - lb > 1)
{
int mid = (lb + ub) / 2;
if (A[mid] >= k)
{
ub = mid;
}
else
{
lb = mid;
}
}

printf("Output Number:%d\n", ub);

return 0;
}

// 表示をきれいにするためのプログラム
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);
}
}
73 changes: 70 additions & 3 deletions src/spear.c
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);
}
}
90 changes: 87 additions & 3 deletions src/works.c
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)

Choose a reason for hiding this comment

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

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

Copy link
Author

@Sugi-kmmm Sugi-kmmm Jul 2, 2022

Choose a reason for hiding this comment

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

了解いたしました。
また、出力の方も了解です。
修正の期限の方は何時迄でしょうか?

Copy link

@nanashima nanashima Jul 2, 2022

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などですね.(追記:ケースを小さいものに修正しました)
後はでたらめなケースのほとんどでかなり大きめの値を出力しています.

Choose a reason for hiding this comment

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

修正期限は確認します

Choose a reason for hiding this comment

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

修正期限ですが,ちゃんとした日時は未定ですが,
例年では最終課題の締め切りと同じくらいです.
なので,他の課題も考慮しつつ計画的にやっていただければ大丈夫です.

Choose a reason for hiding this comment

The 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);
}
}