https://www.acmicpc.net/problem/5341

 

5341번: Pyramids

The input will be a sequence of integers, one per line. The end of input will be signaled by the integer 0, and does not represent the base of a pyramid. All integers, other than the last (zero), are positive.

www.acmicpc.net

 

문제

A pyramid of blocks is constructed by first building a base layer of n blocks and then adding n-1 blocks to the next layer. This process is repeated until the top layer only has one block.

 

pyramids

 

You must calculate the number of blocks needed to construct a pyramid given the size of the base. For example, a pyramid that has a base of size 4 will need a total of 10 blocks.

입력

The input will be a sequence of integers, one per line. The end of input will be signaled by the integer 0, and does not represent the base of a pyramid. All integers, other than the last (zero), are positive.

 

출력

For each positive integer print the total number of blocks needed to build the pyramid with the specified base.


코드

#include <stdio.h>

int main() {
    int n;
    while (1)
    {
      scanf("%d", &n);

      if (n == 0)
      {
        break;
      }

      int sum = n * (n+1) / 2;
      printf("%d\n", sum);
      
    }
    

    return 0;
}

 

등차수열을 이용하면 된다.

 

 

 

https://www.acmicpc.net/problem/17499

 

17499번: 수열과 시프트 쿼리

첫 번째 줄에 Q개의 연산을 차례대로 수행한 후 a1, a2, …, aN 을 공백을 사이에 두고 출력합니다.

www.acmicpc.net

 

문제

백준 온라인 저지를 여행하다 보면 하나의 수열이 주어지고 여기에 여러 가지 연산을 하는 문제들을 만나볼 수 있습니다.

진수는 백준 온라인 저지에서 문제를 풀다 다음과 같은 문제를 찾았습니다.

길이가 N인 정수 수열 [a1, a2, ..., aN] 이 주어진다. 다음과 같은 연산들을 수행한 후 수열을 출력하는 프로그램을 작성하시오.

  • 1 i x : ai에 정수 x만큼 더한다.
  • 2 s : 수열을 오른쪽으로 s칸 시프트한다.
  • 3 s : 수열을 왼쪽으로 s칸 시프트한다.

수열을 오른쪽으로 한 칸 시프트하면 수열 [a1, a2, …, aN-1, aN] 은 [aN, a1, a2, …, aN-1] 이 되고

수열을 왼쪽으로 한 칸 시프트하면 수열 [a1, a2, …, aN-1, aN] 은 [a2, …, aN-1, aN, a1] 이 된다.

진수는 빠르게 코딩하여 제출하였는데 '시간 초과' 판정을 받았습니다.

진수가 작성한 코드는 시프트 연산을 수행할 때마다 반복문이 N번 실행되어 너무 느리기 때문입니다.

진수는 이 문제를 풀어 '맞았습니다!!' 를 띄워줄 누군가를 기다리고 있습니다.

입력

첫 번째 줄에 수열의 길이 N (2 ≤ N ≤ 200,000) 과 연산의 개수 Q (1 ≤ Q ≤ 200,000) 가 주어집니다.

두 번째 줄에는 정수 a1, a2, ..., aN (-10,000 ≤ ai ≤ 10,000) 이 주어집니다.

다음 Q개의 줄에는 각 줄 마다 연산이 주어집니다. 

 

출력

첫 번째 줄에 Q개의 연산을 차례대로 수행한 후 a1, a2, …, aN 을 공백을 사이에 두고 출력합니다.

 

제한

  • 1 ≤ i  N
  • -10,000 ≤ x ≤ 10,000
  • 1 ≤ s  N-1

코드

#include <stdio.h>


int main(void) {
	int n, q, s = 0;
	long arr[200020] = { 0 };
	int x, a, b = 0;
	scanf("%d %d", &n, &q);

	for (int i = 0; i < n; i++)
	{
		scanf("%ld", &arr[i]);
	}
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &x);
		if (x == 1)
		{
			scanf("%d %d", &a, &b);
			a--;
			arr[(s+a)%n] += b;
		}else if (x == 2)
		{
			scanf("%d", &a);
			s = (s + n - a) % n;
		}else {
			scanf("%d", &a);
			s = (s + a) % n;
		}
		
		
	}
	
	for (int i = 0; i < n; i++)
	{
		printf("%ld ", arr[(s+i)%n]);
		
	}
	
	
	
}

 

 

이 멋진 수열에 쿼리를!

해당 문제를 해결하고 이 멋진 수열에 쿼리를! 프로필 배경을 획득했다!

 

'C > solved' 카테고리의 다른 글

C) 백준 5341번 : Pyramids  (0) 2023.06.03
C) 백준 23234 : The World Responds  (0) 2023.06.03
C) 백준 27327번 : 時間 (Hour)  (0) 2023.06.03
C) 백준 27331번 : 2 桁の整数 (Two-digit Integer)  (0) 2023.06.03
C) 백준 10189번 : Hook  (0) 2023.06.03

https://www.acmicpc.net/problem/23234

 

23234번: The World Responds

In many introductory computer programming classes, the first program that students learn to write just prints “Hello, world!” It is used as a first assignment because it is a simple program that produces output. The program dates back to at least 1974,

www.acmicpc.net

 

문제

In many introductory computer programming classes, the first program that students learn to write just prints “Hello, world!” It is used as a first assignment because it is a simple program that produces output. The program dates back to at least 1974, when Brian Kernighan used it as an example in a C programming tutorial. Its popularity has grown since then. Louisiana Tech University's ACM chapter has a Hello World project that has collected versions of this program in almost 200 different computer languages.

While “Hello, World!” is a nice and simple first program, it does have one drawback. The program says hello to the world, but the world does not respond! This one-sided conversation is starting to become awkward after more than 35 years. For this problem, write a program that returns greetings from the world to the program.

 

많은 프로그래밍 입문 수업에서 학생은 제일 먼저 "Hello, world!"를 출력하는 프로그램을 작성하는 법을 배웁니다. 이것이 첫 번째 과제로 쓰이는 이유는 출력을 만드는 단순한 프로그램이기 때문입니다. 이 프로그램은 1974년, 브라이언 커니핸이 C 프로그래밍 튜토리얼의 예시로 사용하면서 이후 명성을 떨쳤습니다. 루이지애나 공과대의 ACM은 200개의 컴퓨터 언어로 쓰여진 버전을 모아둔 Hello World 프로젝트를 보유하고 있습니다.

"Hello, World"는 간단하면서도 좋은 첫 프로그램이지만, 하나의 문제를 가지고 있습니다. 바로 프로그램은 세상에 Hello를 외치지만, 세상이 대답하지 않는다는 것입니다! 이 일방향 소통은 35년이 넘게 지난 지금 생각해보면 참 이상합니다. 이 문제를 해결하기 위해, 세상이 프로그램에 답장을 해주는 프로그램을 작성합시다.

입력

There is no input for this problem.

이 문제의 입력은 없습니다.

 

출력

Print one line of output: The world says hello!

The world says hello! 한 줄을 출력합니다.

 

코드

#include <stdio.h>


int main()
{
	
	printf("The world says hello!");
	

	return 0;
}

 

 

 

 

 

https://www.acmicpc.net/problem/27327

 

27327번: 時間 (Hour)

X 日は何時間か,単位 (時間) を省いて出力せよ.

www.acmicpc.net

 

문제

1 日は 24 時間である.

整数 X が与えられる. X 日は何時間か求めよ.

입력

入力は以下の形式で標準入力から与えられる.

 

출력

X 日は何時間か,単位 (時間) を省いて出力せよ.

제한

  • 1 ≦ X ≦ 365.
  • X は整数である.

코드

#include <stdio.h>


int main()
{
	int n;
	scanf("%d", &n);
	printf("%d", n * 24);
	

	return 0;
}

 

 

 

 

 

https://www.acmicpc.net/problem/27331

 

27331번: 2 桁の整数 (Two-digit Integer)

2 つの数字 A, B が与えられる. 十の位が A であり,一の位が B である 2 桁の正の整数を出力せよ.

www.acmicpc.net

 

문제

2 つの数字 A, B が与えられる.

十の位が A であり,一の位が B である 2 桁の正の整数を出力せよ.

 

2개의 숫자 A와 B가 주어집니다.

10의 자리가 A이고, 1의 자리가 B인 2자리 수를 출력하세요.

입력

入力は以下の形式で与えられる.

첫째 줄에는 A가 주어집니다.

둘째 줄에는 B가 주어집니다.

출력

十の位が A であり,一の位が B である 2 桁の正の整数を出力せよ.

10의 자리가 A이고, 1의 자리가 B인 2자리 수를 출력합니다.

 

제한

A는 1, 2, 3, 4, 5, 6, 7, 8, 9 중 하나입니다.

B는 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 중 하나입니다.


코드

#include <stdio.h>


int main()
{
	int n, x;
	scanf("%d", &n);
	scanf("%d", &x);
	printf("%d%d",n,x);
	

	return 0;
}

 

 

 

 

 

'C > solved' 카테고리의 다른 글

C) 백준 23234 : The World Responds  (0) 2023.06.03
C) 백준 27327번 : 時間 (Hour)  (0) 2023.06.03
C) 백준 10189번 : Hook  (0) 2023.06.03
C) 백준 26561번 : Population  (0) 2023.06.03
C) 백준 24900번 : 한별 찍기  (0) 2023.06.03

https://www.acmicpc.net/problem/10189

 

27331번: 2 桁の整数 (Two-digit Integer)

2 つの数字 A, B が与えられる. 十の位が A であり,一の位が B である 2 桁の正の整数を出力せよ.

www.acmicpc.net

문제

Print out the word Hook as shown below.

입력

Print out the word Hook as shown below.

출력

 


코드

#include <stdio.h>


int main()
{
	
	printf("#  # #### #### #  #\n");
	printf("#### #  # #  # # #\n");
	printf("#### #  # #  # # #\n");
	printf("#  # #### #### #  #\n");


	

	return 0;
}

 

 

 

 

 

 

https://www.acmicpc.net/problem/26561

 

26561번: Population

The first line of input will contain a single integer n that indicates the number of lines to follow. Each line will consist of two integers, p and t, where p is the beginning population, and t is the amount of time that will pass. Both p and t will be bet

www.acmicpc.net

 

문제

In Emily’s country it is estimated that a person dies every 7 seconds, and a person is born every 4 seconds. Given a beginning population, estimate the population after a certain period of time.

입력

The first line of input will contain a single integer n that indicates the number of lines to follow. Each line will consist of two integers, p and t, where p is the beginning population, and t is the amount of time that will pass. Both p and t will be between the number 1 and 2,000,000,000.

 

출력

Output the estimated population after the period of time based on the above statistics.


코드

#include <stdio.h>


int main(void) {
	int n, p, t, pop;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d %d", &p, &t);
		pop = p - (t/7) + (t/4);
		printf("%d\n", pop);
	}


    return 0;
}

 

 

'C > solved' 카테고리의 다른 글

C) 백준 27331번 : 2 桁の整数 (Two-digit Integer)  (0) 2023.06.03
C) 백준 10189번 : Hook  (0) 2023.06.03
C) 백준 24900번 : 한별 찍기  (0) 2023.06.03
C) 백준 25625번 : 샤틀버스  (0) 2023.06.03
C) 백준 13597 : Tri-du  (0) 2023.06.03

https://www.acmicpc.net/problem/24900

 

24900번: 한별 찍기

한별이를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

 

문제

한별이를 출력하는 프로그램을 작성하시오.

입력

 

출력

한별이를 아래 예제 출력과 같이 출력한다.


코드

#include <stdio.h>

int main(void) 
{
	printf("                                                           :8DDDDDDDDDDDDDD$.                                           \n");
	printf("                                                      DDDNNN8~~~~~~~~~~=~7DNNDNDDDNNI                                   \n");
	printf("                                                  ?NNDD=~=~~~~~~~~~~~~~~~~~=~~==~=INNDNN7                               \n");
	printf("                                               +NDDI~~~~~~~~~~~~~~~~~~~~~~~=~~========~ODND+                            \n");
	printf("                                            :NND~~~~~~~~~~~~~~~~~~~~~~~~~~~=~~============7NDN                          \n");
	printf("                                          $DD$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=~~==============~DNN                        \n");
	printf("                                        $DD=~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=~~=================NND                      \n");
	printf("                                       ND7~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=~~===================DD7                    \n");
	printf("                                     ~DD=~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=======================8DN.                  \n");
	printf("                                    8DO~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=========================DD                  \n");
	printf("                                   8N~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=~~=======================DN                 \n");
	printf("                                  NN::::::::~~~~~~~~~~~=~~~~~~~~~~~~~~~~~~~=~~========================DDO               \n");
	printf("                                 $D$:::::::::::::::~~~~DD~~~~~~~~~~~~~~~~~~=~~=========================DN.              \n");
	printf("                                 D8:::::::::::::::::::DN=::~~~~~~~~~~~~~~~~=~~======================~~:~DN              \n");
	printf("                                DN:::::::::::::::::::ONO::::::::::::::::::::~~~~~~~~~~~~:::::::::::::::::DN             \n");
	printf("                               DN::::::::::::::::::::NN.:::::::::::::::::::::::::::DN::::::::::::::::::::$DO            \n");
	printf("                               DD:::::::::::::::::::DNI:::::::::::::::::::::::::::::D=::::::::::::::::::::NN            \n");
	printf("                              NN~~~~:::::$N?:::::::.NN::::::::::::::::::::::::::::::ND.:::::::::::::::::::+N8           \n");
	printf("                              N7~~~~~~~~OD7::::::::~DD::::::::::::::::::::::::::::::~D$::::::::::::::::::::DN           \n");
	printf("                             NN~~~~~~~~IDZ~~~~~::::DN~:::::::::::::::::::::::::::::::DN::::::::::::::::::::=N~          \n");
	printf("                             DD~~~~~~~~NN~~~~~~~~~=NN::::::::::::::::::::::::::::::::DN:::::::::::::::~~====NN          \n");
	printf("                            8D~~~~~~~~ND~~~~~~~~~~~ND~~~~~~~~:::::::::::::::::::::::::N7:::~~===============NN          \n");
	printf("                            DD~~~~~~~ON+~~~~~~~~~~~ND~~~~~~~~~~~~~~~~~~~=+NZ==========NN====================~ND         \n");
	printf("               :DD7   DNDD. N8~~~~~~~NN~~~~~~~~~~DDND~~~~~~~~~~~~~~~~~~~~ND~~=========DD=====================ND         \n");
	printf("               N~:DDNNN .8NDN~~~~~~~$D=~~~~~~~~+ND.DD~~~~~~~~~~~~~~~~~~~=DD~~=========~D+====================DN         \n");
	printf("              :D     .  ..~ND~~~~~~~NN~~~~~~~+NN$..ND~~~~~~~~~~~~~~~~~~~7N=~~=========~ND=======~============ON         \n");
	printf("              NN       ...:N?~~~~~~~N=~~~~~NNNI.. .7D+~~~~~~~~~~~~~~~~~=8NN~~==========NN=======N============$N         \n");
	printf("         N  ODN       ....DN~~~~~~~DD=8NNND$..     .DD~~~=~~~~~~~~~~~~~=NNDD=~=========8D~======NN===========~N$        \n");
	printf("    N? =NN  ND      .....NND~~~~~~~DDNN:...        .ND=~DNN~~~~~~~~~~~~=DN.DN~=========?N+======NN============ND        \n");
	printf("   $D? DN    DZ    ....ND8NN~~~~~~$D                .DD~NNDD~~~~~~~~~~~~D8..DN=========~DN======NN============DN        \n");
	printf("   DN ~N~   NN    ..:~NN..NZ~~~~~~DN                  NNN8.ND~~~~NDN?~~~DZ...7DD=======~NN======NN============DN        \n");
	printf("   ND DD    :DN.  ..ND$  .N?~~~~~=NNN                   . ..DDD$~N8OND8=N+   ..DDDZ~====NN======+D+===========ND        \n");
	printf("   NO         DD  ZDN    8NO~~~~~~NNN..DDDNN7               ...NND...:DDD:     .:.NDND=~DD======~DO===========DN        \n");
	printf("              DNDDN:.    DN~~~~~~=NNNN.ODNNNNDDNNO              ...     .         ...DNNNN=======ND===========DD        \n");
	printf("       INDN7    DD.     .DD~~~~~=IDND:.:~.....?DNDNN.                        ...... ....$D=======ND===========ND        \n");
	printf("       NN        ND.    8N=~~~~$ND::.:=~:.~=......=ND~                 .NNNNNNNNNNNNNNN.~N+======NN===========DN        \n");
	printf("       $DD        DN:   DD~~~~7NO...~==.:~~:.....                      NNNND? ..::..7NZ.:N?======8D~==========ZN        \n");
	printf("       DN?     ~D: DND.?D~~~~~DD....~:.~=~.......                            ....~=:.:~..ND======~N$==========~DO       \n");
	printf("       ND    ..DD.  .DNDN=~~~~DI.......:.........                           ....=~..~~~..DN======~DD===========NN       \n");
	printf("       DDD  :.:DD.  . DDI~~~~~ND................        .DNNNNNNNNNN7      ....=~:.:~~...NN=======ND===========?D~      \n");
	printf("       8D. ...OD..    DD~~~~~~+ND ............          NN:~::::~~~8N      ........~~...:ND=======DN============NN      \n");
	printf("       DDI:...ND     .D7~~~~~~~7NN ..........           ID8::::::::8D      .............:DN=======ON============NN      \n");
	printf("        ~NNND.N=.   .NN~~~~~~~~~NDN8                       ~::::::~N8       .............DN========D=============NI     \n");
	printf("               DDNNN.ND~~~~~~~~DD =DND                                       ............DN========N+~===========NN     \n");
	printf("                   ~:N=~~~~~~~~DD   .DDDD                                       ........ NN========DD============8D     \n");
	printf("                    8N~~~~~~~~~ND    . .7NDDD? .                                      .8DDN========NN=============D:    \n");
	printf("                    DD~~~~~~~~~DND:         IDNNND$.                           .+DNNNNDNIDN========DD=============DD    \n");
	printf("                    ND~~~~~~~~ZN 7DD .. .:DDNDDNNDNNNNDDNDND8$?===+$8DDNNNDDDDDN8I~DN====8N========NN=============NN    \n");
	printf("                    DD~~~~~~~~8N   DD.  .NN~~~~.~~=DNDNO.:7ODDDDNNDD8DDDND=~~~ =~~~ON====8N========DN=============DN    \n");
	printf("                    ND~~~~~~~~DN    ZDD  DN~~~ ~~~~~=.7DDD+.......8NNN==~~~~~ ~~~~~ONN$==DN========8N=============ON    \n");
	printf("                    ND~8N~=~~~ZN      DDODN=~.~~~~~=.~~~~INDNNNNDNN~~~~~~~~:~~~~~~~DN~ND=DN========DD=========~ND=8N    \n");
	printf("                    IN=NDDI~~~~D8       DNN::~~~~~.~~~~~=.~~ND~~ND~~~~~~~~.~~~~~~~~NN  NDNN====ND==ND~D?======DNN=ND    \n");
	printf("                     DNNI8ND=~~DN:       ZN=~~~~~ ~~~~~.~~~~DD~=DD~~~~~~~ ~~~~~~~=.ND. . ND===DNDD=NDDNN=====8NZDDDN    \n");
	printf("                      NND  IDNDNNN+       D+~~~:~~~~~~ ~~~~~DDNNN+~~~~~~~~~~~~~~:=?N7   .ND=~ND  DNNN~ID====ND7 NNN     \n");
	printf("                       ID                 ND~~ ~~~~~:.~~~7DDN7IDNN==~~ ~~~~~~~~ ~~DN   .:N?DDDDD NND  8N~=DDD  ZNN      \n");
	printf("                                          NN~:~~~~~ =7DDDD+8N  :N8DDZ.~~~~~~~~.~~~DD.   NDD+ . DN=     OND+             \n");
	printf("                                          DND~~~=8DNDDZ=~~ ND   NN~INND~~~~~.~~~~ND .    .    ..IDD                     \n");
	printf("                                         DDNNNDNNN+~~~~~~.7N.    ND~~~NDDI~ ~~~~=NNN             .DDI                   \n");
	printf("                                        DN=~~~~.=~~~~~~ ~~DN     +N+~~~~+DNDD~~~NNNND.            ..ND                  \n");
	printf("                                         DDI~~ ~~~~~~~ ~~~ND..  ..ND~~~~:~~~DNDNNNN+            ..7O8ND+                \n");
	printf("                                          .DND=~~~~=::~~=NN.   . . 8D~~.~~~~~~=DN$ODNDNDNNNDNNNNND8+~..                 \n");
	printf("                                             8DNNI=.~~~~=NDDNNNNDDNDNN.~~~~~IDDNDND7:.                                  \n");
	printf("                                                ?DNNDD?~DD          ~NN~~=NDD$                                          \n");
	printf("                                                     :DDD.            NNNN=                                               ");
}

 

 

 

 

 

'C > solved' 카테고리의 다른 글

C) 백준 10189번 : Hook  (0) 2023.06.03
C) 백준 26561번 : Population  (0) 2023.06.03
C) 백준 25625번 : 샤틀버스  (0) 2023.06.03
C) 백준 13597 : Tri-du  (0) 2023.06.03
C) 백준 24736 : Football Scoring  (0) 2023.06.03

+ Recent posts