Created
August 9, 2017 14:52
-
-
Save lstar2397/1e644ffa4ae0195724e4235d10c2211a to your computer and use it in GitHub Desktop.
[NYPC2016_본선문제] "나만의 농장 운영하기: 심고 수확하기" 풀이
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
| #include <stdio.h> | |
| #include <math.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| int cropCount; | |
| int harvestTurn[100][100]; | |
| struct Map | |
| { | |
| char data[101][101]; // 맵 데이터 | |
| int weight; // 가로 길이 | |
| int height; // 세로 길이 | |
| } map; | |
| struct WorkMan | |
| { | |
| int turn; // 턴 | |
| int money; // 자금 | |
| struct Location | |
| { | |
| int x; | |
| int y; | |
| } location; | |
| } workMan; | |
| struct Crop | |
| { | |
| char name[20]; // 이름[영소문자] | |
| int price; // 심을 때 필요한 비용 | |
| int income; // 수확할 때 얻을 수 있는 금액 | |
| int turn; // 수확할 수 있을 때까지 걸리는 턴 | |
| } crop[20]; | |
| struct Plow | |
| { | |
| int turn; // 턴 | |
| int price; // 비용 | |
| } plow; | |
| void Initialize(); | |
| void InputMapData(); | |
| void InputCropData(); | |
| void Move(int x, int y); | |
| void Plow(); | |
| void Plant(int index); | |
| void Harvest(); | |
| void Action(); | |
| int main() | |
| { | |
| Initialize(); | |
| scanf("%d", &workMan.money); // 입력 - 초기 자금 | |
| scanf("%d %d", &plow.turn, &plow.price); // 입력 - 밭을 만드는데 소요되는 (턴, 비용) | |
| scanf("%d %d", &workMan.location.x, &workMan.location.y); // 입력 - 일꾼의 시작 위치(x, y) *좌표는 지도의 왼쪽 제일 위 칸이 (1, 1)에 해당한다. | |
| scanf("%d %d", &map.weight, &map.height); // 입력 - 지도의 크기(weight, height) *(1 <= weight, height <= 100) | |
| InputMapData(); // 입력(for[height]->for[weight]) - 지도 데이터 | |
| scanf("%d", &cropCount); // 입력 - 심을 수 있는 작물의 종류 개수 | |
| InputCropData(); // 입력(for[cropCount]) - 작물 데이터(이름[영소문자], 수확할 수 있을 때까지 걸리는 턴, 심을 때 필요한 비용, 수확할 때 얻을 수 있는 금액) | |
| Action(); | |
| } | |
| void Initialize() | |
| { | |
| workMan.turn = 0; | |
| } | |
| void InputMapData() | |
| { | |
| for (int i = 0; i < map.height; i++) | |
| for (int j = 0; j < map.weight; j++) | |
| scanf(" %c", &map.data[i][j]); | |
| } | |
| void InputCropData() | |
| { | |
| for (int i = 0; i < cropCount; i++) | |
| { | |
| scanf("%s", &crop[i].name); | |
| scanf("%d", &crop[i].turn); | |
| scanf("%d", &crop[i].price); | |
| scanf("%d", &crop[i].income); | |
| } | |
| } | |
| void Move(int x, int y) | |
| { | |
| workMan.turn += abs(x - workMan.location.x) + abs(y - workMan.location.y); | |
| workMan.location.x = x; | |
| workMan.location.y = y; | |
| } | |
| void Plow() | |
| { | |
| map.data[workMan.location.y][workMan.location.x] = '#'; | |
| workMan.turn += plow.turn; | |
| workMan.money -= plow.price; | |
| } | |
| void Plant(int index) | |
| { | |
| workMan.money -= crop[index].price; | |
| map.data[workMan.location.y][workMan.location.x] = index; | |
| workMan.turn++; | |
| harvestTurn[workMan.location.y][workMan.location.x] = workMan.turn + crop[index].turn; | |
| } | |
| void Harvest() | |
| { | |
| int index = map.data[workMan.location.y][workMan.location.x]; | |
| map.data[workMan.location.y][workMan.location.x] = '#'; | |
| workMan.money = crop[index].income; | |
| workMan.turn++; | |
| } | |
| void Action() | |
| { | |
| printf("%d move %d %d\n", workMan.turn, 4, 2); | |
| Move(4, 2); | |
| printf("%d plow\n", workMan.turn); | |
| Plow(); | |
| printf("%d plant berry\n", workMan.turn); | |
| Plant(0); | |
| printf("%d move %d %d\n", workMan.turn, 3, 2); | |
| Move(3, 2); | |
| printf("%d plant berry\n", workMan.turn); | |
| Plant(0); | |
| printf("%d move %d %d\n", workMan.turn, 2, 2); | |
| Move(2, 2); | |
| printf("%d plant berry\n", workMan.turn); | |
| Plant(0); | |
| printf("%d move %d %d\n", workMan.turn, 4, 2); | |
| Move(4, 2); | |
| workMan.turn = harvestTurn[workMan.location.y][workMan.location.x]; | |
| printf("%d harvest\n", workMan.turn); | |
| Harvest(); | |
| printf("%d move %d %d\n", workMan.turn, 3, 2); | |
| Move(3, 2); | |
| workMan.turn = harvestTurn[workMan.location.y][workMan.location.x]; | |
| printf("%d harvest\n", workMan.turn); | |
| Harvest(); | |
| printf("%d move %d %d\n", workMan.turn, 2, 2); | |
| Move(2, 2); | |
| workMan.turn = harvestTurn[workMan.location.y][workMan.location.x]; | |
| printf("%d harvest\n", workMan.turn); | |
| Harvest(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment