오랜만에 복귀한 DIV2.. 결과는 무척 아쉬웠다..
초반부터 객기를 부려서 1000부터 오픈했지만.. 해석이안되서 포기하고 500 250 순으로 열었다.. -_-;;
500 250은 쉽게 풀고.. 나중에 1000도 도전했지만.. 정말 아쉽게 못풀었다.. 흑.. ㅠ_ㅠ 단 한줄때문에.. ㅠ_ㅠ
방 5등 전체 114등.. 헐.. ㅠ_ㅠ 문제는 쉬웠는데 넘 아쉽다..
이젠 DIV2에서도 밀리는구나.. ㅠ_ㅠ
아무리 그래도 넘 쪼금오른거 아니가?
[250] WhiteCells
Problem Statement
A chessboard is an 8 x 8 grid of cells. Within each column and within each row, cells alternate between black and white. The cell in the upper left corner (0, 0) is white. You are given a vector <string> board, where the j-th character of the i-th element is 'F' if the cell in the j-th column from the left and i-th row from the top is occupied, or '.' if it is empty. Return the number of occupied white cells on the board.
Definition
Class:
WhiteCells
Method:
countOccupied
Parameters:
vector <string>
Returns:
int
Method signature:
int countOccupied(vector <string> board)
(be sure your method is public)
Constraints
-
board will contain exactly 8 elements.
-
Each element of board will contain exactly 8 characters.
-
board will contain only the characters '.' and 'F'.
Examples
0)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
input으로 chess판이 주어지고.. 흰색 칸에 놓여있는 unit의 개수를 세는 문제..
아무리 easy라지만.. 너무한거 아냐.. -_-
1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <vector>
5 #include <string>
6 using namespace std;
7
8 class WhiteCells {
9 public:
10
11 int countOccupied (vector<string> board)
12 {
13 char map[10][10];
14 int i, j, cnt;
15 for (i = 0; i < 8; i++) {
16 strcpy(map[i], board[i].c_str());
17 }
18 cnt =0;
19 for (i = 0; i < 8; i++) {
20 for (j = 0; j < 8; j++) {
21 if ((i+j)%2 == 0) {
22 if (map[i][j] == 'F')
23 cnt++;
24 }
25 }
26 }
27 return cnt;
28 }
29
30 };
[500] ObtainingDigitK
Problem Statement
Return the smallest non-negative integer that can be added to originalNumber such that the resulting integer contains at least one digit k. All numbers should have no extra leading zeroes.
Definition
Class:
ObtainingDigitK
Method:
minNumberToAdd
Parameters:
string, int
Returns:
int
Method signature:
int minNumberToAdd(string originalNumber, int k)
(be sure your method is public)
Constraints
-
originalNumber will contain between 1 and 50 characters, inclusive.
-
originalNumber will contain only digits ('0'-'9').
-
originalNumber will represent a non-negative integer with no extra leading zeroes.
-
k will be between 0 and 9, inclusive.
Examples
0)
"153"
7
Returns: 4
153 + 4 = 157
1)
"158"
7
Returns: 9
158 + 9 = 167
2)
"7853192"
2
Returns: 0
Digit '2' is already present in the number.
3)
"99999999999999999999999999999999999999999999999"
0
Returns: 1
Add 1 to get a lot of zeroes.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
임의의 숫자가 들어오면 덧셈을 한 결과에 K가 들어있도록 더해야하는 최소 수 구하기..
역시 별로 어렵지않지만.. 약간 tricy할수도있다..
나같은경우 귀찮은거 생각하기 싫어서.. 예전에 만들어논 big int루다가.. ㅋㅋ
물론 내가 만든 big int는 아니고.. SCCC누군가가 만든거..
1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <vector>
5 #include <string>
6 using namespace std;
7
8 void add(char* a, char* b, char* c)
9 {
10 int len_a, len_b, len, i, j, k;
11
12 len_a=strlen(a), len_b=strlen(b);
13 len=len_a>len_b?len_a:len_b;
14 for(i=len_a-1, j=len_b-1, k=len-1; i>=0 || j>=0; i--, j--, k--){
15 if(i>=0 && j>=0) c[k]=a[i]+b[j]-'0';
16 else if(i>=0) c[k]=a[i];
17 else c[k]=b[j];
18 }
19 for(i=len-1; i>0; i--) if(c[i]>9+'0') c[i-1]++, c[i]-=10;
20 c[len]='\0';
21 if(c[0]>9+'0'){
22 for(i=len+1; i>0; i--)
23 c[i]=c[i-1];
24 c[0]='1', c[1]-=10;
25 }
26 }
27
28 int check(char* buf, int len, char ch)
29 {
30 int i;
31 for (i = 0; i < len; i++) {
32 if (buf[i] == ch)
33 return 1;
34 }
35 return 0;
36 }
37
38 class ObtainingDigitK {
39 public:
40
41 int minNumberToAdd(string originalNumber, int k)
42 {
43 int i, fl;
44 char str1[1000], str2[1000], str3[1000];
45 fl = 0;
46 strcpy(str1, originalNumber.c_str());
47 for (i = 0; ; i++) {
48 sprintf(str2, "%d", i);
49 add(str1, str2, str3);
50 if (check(str3, strlen(str3), k+'0'))
51 break;
52 }
53 return i;
54 }
55
56 };
[1000] ProgramingDevice
Problem Statement
You work in a company that produces measuring devices. The software for each device is stored in reprogrammable memory. To program a device, you must connect it to a personal computer and transmit data to the device's reprogrammable memory through a serial interface. Your task is to make this process as efficient as possible.
You are given two vector <int>s offset and size. Each corresponding pair of elements in offset and size describes a piece of data that must be transmitted to the device. The i-th piece of data consists of size[i] consecutive bytes that must be written starting at the address in offset[i]. To successfully program a device, you must write every piece of the given data. Memory addresses that are not referenced in this data are not important - so you can write anything to those addresses, or write nothing at all to them.
Data is transmitted from the computer to the device through packets. Each packet can contain a maximum of maxData bytes of consecutive data that will be written to a specified memory address. Return the minimum possible total number of packets required to transmit all of the given data to the device.
Definition
Class:
ProgrammingDevice
Method:
minPackets
Parameters:
vector <int>, vector <int>, int
Returns:
int
Method signature:
int minPackets(vector <int> offset, vector <int> size, int maxData)
(be sure your method is public)
Notes
-
Assume that the reprogrammable memory of the measuring device is infinitely large.
Constraints
-
offset will contain between 1 and 50 elements, inclusive.
-
offset and size will contain the same number of elements.
-
Each element of offset will be between 0 and 1,000,000,000, inclusive.
-
Each element of size will be between 1 and 1,000,000,000, inclusive.
-
None of the pieces of data described by offset and size will overlap.
-
maxData will be between 1 and 2,000,000,000, inclusive.
Examples
0)
{0, 10, 20, 30}
{8, 5, 3, 11}
6
Returns: 6
Send 15 bytes starting from offset 0 in 3 packets. Only 13 of those 15 bytes are meaningful. There are 2 dummy bytes starting from offset 8. Then, send 3 bytes starting from offset 20 in 1 packet. Finally, send 11 bytes starting from offset 30 in 2 packets. A total of 6 packets are sent.
1)
{0, 10, 20, 30}
{8, 2, 3, 11}
6
Returns: 5
Send 12 bytes starting from offset 0 in 2 packets. Then, send 3 bytes starting from offset 20 in 1 packet. Finally, send 11 bytes starting from offset 30 in 2 packets. A total of 5 packets are sent.
2)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
훔.. 이거는 문제를 설명하기가 힘들다.. -_-;;
offset과 size가 각각 배열로 들어오고(각각이 쌍이다).. 최대 packet 크기가 들어온다..
각각 메모리 offset이 시작 주소이고 size만큼 data를 써야하는데..
그러게 하기 위해서 전송해야하는 최대 packet수를 구하는 문제..
메모리 중간에 생기는 구멍에는 data를 쓰던지 말던지 상관없다.
그리고 메모리 주소가 overlap되는 input은 안들어온다.