CF #263,
I did not play it yesterday. I wrote it today. The first three questions are not difficult.
A. Appleman and Easy Tasktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
GivenNLimit × limitNCheckerboard. Each cell of the board has either character 'x', or character 'O'. Is it true that each cell of the board has even number of adjacent cells with 'O '? Two cells of the board are adjacent if they share a side.
Input
The first line contains an integerN(1 digit ≤ DigitNLimit ≤ limit 100). ThenNLines follow containing the description of the checkerboard. Each of them containsNCharacters (either 'X' or 'O') without spaces.
Output
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
Sample test (s) input
3xxoxoxoxx
Output
YES
Input
4xxxoxoxooxoxxxxx
Output
NO
Question: determine the number of 'o' in the top, bottom, left, and right directions of a point, which is an even number and outputs YES. Otherwise, NO is output.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<vector>typedef long long LL;using namespace std;char mp[110][110];int n;int main(){ while(cin>>n) { int ok=1; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) cin>>mp[i][j]; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { int cnt=0; if(mp[i+1][j]=='o') cnt++; if(mp[i-1][j]=='o') cnt++; if(mp[i][j-1]=='o') cnt++; if(mp[i][j+1]=='o') cnt++; if(cnt&1) { ok=0; break; } } } if(ok) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0;}
B. Appleman and Card Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Appleman hasNCards. Each card has an uppercase letter written on it. Toastman must chooseKCards from Appleman's cards. Then Appleman shoshould give Toastman some coins depending on the chosen cards. Formally, for each Toastman's cardIYou shoshould calculate how much Toastman's cards have the letter equal to letter onITh, then sum up all these quantities, such a number of coins Appleman shoshould give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
Input
The first line contains two integersNAndK(1 digit ≤ DigitKLimit ≤ limitNMemory ≤ memory 105). The next line containsNUppercase letters without spaces-I-Th letter describesI-Th card of the Appleman.
Output
Print a single integer-the answer to the problem.
Sample test (s) input
15 10DZFDFZDFDDDDDDF
Output
82
Input
6 4YJSNPI
Output
4
Note
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. for each card with D he will get 9 coins and for the additional card he will get 1 coin.
You can sort and calculate the hash.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<vector>typedef long long LL;using namespace std;int hash[30];int cmp(int a,int b){ return a>b;}int main(){ int n,k; char c; while(cin>>n>>k) { memset(hash,0,sizeof(hash)); for(int i=0;i<n;i++) { cin>>c; hash[c-'A']++; } sort(hash,hash+26,cmp); LL sum=0; for(int i=0;i<26;i++) { if(k==0) break; if(k>=hash[i]) { sum+=(LL)hash[i]*hash[i]; k-=hash[i]; } else { sum+=(LL)k*k; k=0; } } cout<<sum<<endl; } return 0;}
C. Appleman and Toastmantime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Appleman and Toastman play a game. Initially Appleman gives one groupNNumbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman.
- Each time Appleman gets a group consisting of a single number, he throws this group out. each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input
The first line contains a single integerN(1 digit ≤ DigitNLimit ≤ limit 3 · 105). The second line containsNIntegersA1,A2 ,...,AN(1 digit ≤ DigitAILimit ≤ limit 106)-the initial group that is given to Toastman.
Output
Print a single integer-the largest possible score.
Sample test (s) input
33 1 5
Output
26
Input
110
Output
10
Note
Consider the following situation in the first example. initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. both of them shocould be given to Toastman. when Toastman ES group [1], he adds 1 to score and gives the group to Appleman (he will throw it out ). when Toastman groups ES group [3, 5], he adds 8 to the score and gives the group to Appleman. appleman splits [3, 5] in the only possible way: [5] and [3]. then he gives both groups to Toastman. when Toastman es [5], he adds 5 to the score and gives the group to Appleman (he will throws it out ). when Toastman es [3], he adds 3 to the score and gives the group to Appleman (he will throws it out ). finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. this is the optimal sequence of actions.
Count. If you throw a minimum number each time, the maximum value is obtained.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<vector>typedef long long LL;using namespace std;LL num[300000+100];int main(){ int n; while(~scanf("%d",&n)) { LL sum=0; for(int i=1;i<=n;i++) scanf("%d",&num[i]); sort(num+1,num+n+1); for(int i=1;i<=n;i++) sum+=num[i]*(i+1); cout<<sum-num[n]<<endl; } return 0;}
How does CF show out of memory?
Windows 7 often has this problem, and Windows XP systems also have this problem. In this case, I have also encountered a Windows XP system. Simply re-register the game. The English meaning is caused by insufficient memory, but the real problem I think you have understood is that the system cannot be used for the excess memory space of the game, so where is the 4 GB memory? In addition to the memory occupied by the system, CF is swallowed up. If there is a 3250m of air, a gas pump is always aspirated without exhaust, do you say this air is enough? A game only eats memory and does not release memory. Can you say there be extra memory for the game? The problem that the game does not release memory has already been updated in several versions.
This is written by others. You can try.
An out of memory solution:
Out of memory
The memory is insufficient.
As a programmer with years of WIN32 C ++ development experience, I do not agree with WIN7
Because I do not think that the system's pre-read will occupy the user address space. At least, the pre-read function is a separate system service and an independent process. If the system memory is insufficient, windows will certainly prompt that you have never encountered it. A small triangle in the lower right corner will prompt that the virtual memory is too small.
This problem has been caused by the memory leakage of the DN program or the amount of memory requested exceeds 2 GB because the memory space is not taken into account, however, every time this BUG occurs, I observe the memory usage, but I find that it is generally 1.5 GB. Therefore, this possibility was ruled out at the beginning, but today I suddenly think of a memory ing file, and the maximum resource package of DN is exactly 0.5 GB.
Therefore, it is extremely likely that this is the cause. (Although opening a file through memory ing does not load the entire file to the memory, it occupies the address space equal to the file size, while the maximum address space of win32 system processes is 4 GB.
The Default User address space is 2 GB, that is to say, as a programmer, the maximum address space of a process is 2 GB, and when the memory is insufficient, the memory usage of the DN process is GB and the resource package address space of GB is approximately 2 GB. Therefore, when the application for memory is made will fail .)
It is difficult to understand these estimates, so let's talk about the solution. (I have no source code for DN, so I can only find a solution from other places.) The following is the focus.
Modify the WINDOWS startup configuration so that the user address space of the process reaches 3 GB.
Windows
7 system:
1. Enter the command line: Click the Start Menu-> enter "cmd" in the search box, and press ctrl + shift +
Press enter (* member mode of the command line)
2. Enter the command: bcdedit/set increaseuserva 3072
Enter
3. restart the system.
XP system:
1. Remove the read-only attributes of the boot file: Start-> RUN input "attrib
C: \ boot. ini-h-r-s "Press ENTER
2. Edit the boot file: Start-> run the input "c: \ boot. ini"
Press enter, in a format similar to "multi (0) disk (0) rdisk (0) partition (1) \ WINDOWS =" Microsoft Windows XP
"/Noexecute = optin/fastdetect" is added at the end of the line "/3 GB"
Save.
3. Restore the boot file read-only and other attributes: Start-> run the input "attrib c: \ boot. ini + h + r + s"
Enter
4. restart the system.
(Remind the XP system to edit the boot file directly on my computer-> properties-> advanced
-> Startup and fault recovery settings-> do not forget to save after editing)... the remaining full text>
How does CF show out of memory?
Windows 7 often has this problem, and Windows XP systems also have this problem. In this case, I have also encountered a Windows XP system. Simply re-register the game. The English meaning is caused by insufficient memory, but the real problem I think you have understood is that the system cannot be used for the excess memory space of the game, so where is the 4 GB memory? In addition to the memory occupied by the system, CF is swallowed up. If there is a 3250m of air, a gas pump is always aspirated without exhaust, do you say this air is enough? A game only eats memory and does not release memory. Can you say there be extra memory for the game? The problem that the game does not release memory has already been updated in several versions.
This is written by others. You can try.
An out of memory solution:
Out of memory
The memory is insufficient.
As a programmer with years of WIN32 C ++ development experience, I do not agree with WIN7
Because I do not think that the system's pre-read will occupy the user address space. At least, the pre-read function is a separate system service and an independent process. If the system memory is insufficient, windows will certainly prompt that you have never encountered it. A small triangle in the lower right corner will prompt that the virtual memory is too small.
This problem has been caused by the memory leakage of the DN program or the amount of memory requested exceeds 2 GB because the memory space is not taken into account, however, every time this BUG occurs, I observe the memory usage, but I find that it is generally 1.5 GB. Therefore, this possibility was ruled out at the beginning, but today I suddenly think of a memory ing file, and the maximum resource package of DN is exactly 0.5 GB.
Therefore, it is extremely likely that this is the cause. (Although opening a file through memory ing does not load the entire file to the memory, it occupies the address space equal to the file size, while the maximum address space of win32 system processes is 4 GB.
The Default User address space is 2 GB, that is to say, as a programmer, the maximum address space of a process is 2 GB, and when the memory is insufficient, the memory usage of the DN process is GB and the resource package address space of GB is approximately 2 GB. Therefore, when the application for memory is made will fail .)
It is difficult to understand these estimates, so let's talk about the solution. (I have no source code for DN, so I can only find a solution from other places.) The following is the focus.
Modify the WINDOWS startup configuration so that the user address space of the process reaches 3 GB.
Windows
7 system:
1. Enter the command line: Click the Start Menu-> enter "cmd" in the search box, and press ctrl + shift +
Press enter (* member mode of the command line)
2. Enter the command: bcdedit/set increaseuserva 3072
Enter
3. restart the system.
XP system:
1. Remove the read-only attributes of the boot file: Start-> RUN input "attrib
C: \ boot. ini-h-r-s "Press ENTER
2. Edit the boot file: Start-> run the input "c: \ boot. ini"
Press enter, in a format similar to "multi (0) disk (0) rdisk (0) partition (1) \ WINDOWS =" Microsoft Windows XP
"/Noexecute = optin/fastdetect" is added at the end of the line "/3 GB"
Save.
3. Restore the boot file read-only and other attributes: Start-> run the input "attrib c: \ boot. ini + h + r + s"
Enter
4. restart the system.
(Remind the XP system to edit the boot file directly on my computer-> properties-> advanced
-> Startup and fault recovery settings-> do not forget to save after editing)... the remaining full text>