Good Bye 2013
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[300005],p[300005],ans[300005];
int cmp(const int x,const int y)
{
return a[x]<a[y];
}
int main()
{
int n,i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
p[i]=i;
}
sort(p,p+n,cmp);
int now=0;
for(i=0;i<n;i++)
{
if(a[p[i]]>=now)
{
ans[p[i]]=a[p[i]];
now=a[p[i]]+1;
}
else
{
ans[p[i]]=now;
now++;
}
}
for(i=0;i<n;i++)
printf("%d ",ans[i]);
printf("\n");
}
}
Many countries have such a New Year or Christmas tradition as writing a letter to Santa including a wish list for presents. Vasya is an ordinary programmer boy. Like all ordinary boys, he is going to write the letter to Santa on the New Year Eve (we Russians actually expect Santa for the New Year, not for Christmas).
Vasya has come up with an algorithm he will follow while writing a letter. First he chooses two strings, s1 anf s2, consisting of uppercase English letters. Then the boy makes string sk, using a recurrent equation sn = sn - 2 + sn - 1, operation '+' means a concatenation (that is, the sequential record) of strings in the given order. Then Vasya writes down string sk on a piece of paper, puts it in the envelope and sends in to Santa.
Vasya is absolutely sure that Santa will bring him the best present if the resulting string sk has exactly x occurrences of substring AC (the short-cut reminds him оf accepted problems). Besides, Vasya decided that string s1 should have length n, and string s2 should have length m. Vasya hasn't decided anything else.
At the moment Vasya's got urgent New Year business, so he asks you to choose two strings for him, s1 and s2 in the required manner. Help Vasya.
The first line contains four integers k, x, n, m (3 ≤ k ≤ 50; 0 ≤ x ≤ 109; 1 ≤ n, m ≤ 100).
In the first line print string s1, consisting of n uppercase English letters. In the second line print string s2, consisting of m uppercase English letters. If there are multiple valid strings, print any of them.
If the required pair of strings doesn't exist, print "Happy new year!" without the quotes.
3 2 2 2
AC AC
3 3 2 2
Happy new year!
3 0 2 2
AA AA
4 3 2 1
Happy new year!
4 2 2 1
Happy new year!
思路:參考別人的程式碼。。。看是看懂了,但感覺自己還真不一定能寫出來。。。暴力列舉,dp,列舉兩個串的頭尾字母和AC個數。每次判斷進行dp遞推。如果i - 2串為A且i - 1串頭為C。dp[i]會多組成一個AC就+1。
下面是程式碼:
#include <stdio.h>
#include <string.h>
const int N = 105;
int k, x, n, m;
__int64 f[N];
char ans[N], s[N], e[N];
void init() {
scanf("%d%d%d%d", &k, &x, &n, &m);
}
void print(char s, char e, int len, int num) {
memset(ans, 0, sizeof(ans));
ans[0] = s; ans[len - 1] = e;
int i, bo = (s == 'A' ? 0 : 1);
for (i = 1; i < len - 1; i++)
ans[i] = 'B';
for (i = 0; i < num; i++) {
ans[bo + 2 * i] = 'A';
ans[bo + 2 * i + 1] = 'C';
}
printf("%s\n", ans);
}
bool ISOK(char s1, char e1, char s2, char e2, int xx, int yy) {
s[1] = s1; e[1] = e1; s[2] = s2; e[2] = e2; f[1] = xx; f[2] = yy;
for (int i = 3; i <= k; i ++) {
s[i] = s[i - 2];
e[i] = e[i - 1];
f[i] = f[i - 1] + f[i - 2] + (e[i - 2] == 'A' && s[i - 1] == 'C');
}
if (f[k] == x)
return true;
return false;
}
bool judge() {
for (char s1 = 'A'; s1 <= 'C'; s1++) {
for (char e1 = 'A'; e1 <= 'C'; e1++) {
if (n == 1 && s1 != e1) continue;
for (char s2 = 'A'; s2 <= 'C'; s2++) {
for (char e2 = 'A'; e2 <= 'C'; e2++) {
if (m == 1 && s2 != e2) continue;
int lx = n - (s1 != 'A') - (e1 != 'C');
int ly = m - (s2 != 'A') - (e2 != 'C');
lx /= 2; ly /= 2;
for (int xx = 0; xx <= lx; xx++)
for (int yy = 0; yy <= ly; yy++) {
if (n == 2 && s1 == 'A' && e1 == 'C' && xx == 0) continue;
if (m == 2 && s2 == 'A' && e2 == 'C' && yy == 0) continue;
if (ISOK(s1, e1, s2, e2, xx, yy)) {
print(s1, e1, n, xx);
print(s2, e2, m, yy);
return true;
}
}
}
}
}
}
return false;
}
void solve() {
if (!judge())
printf("Happy new year!\n");
}
int main() {
init();
solve();
return 0;
}
相關文章
- codeforces Good Bye 2014Go
- 百度推廣賬戶大量被盜 眾多企業SAY GOOD BYEGo
- 【訓練題25:數學+位運算】E : Apollo versus Pan | CF Good Bye 2020Go
- Good:2013年50%的員工將要求BYODGo
- Bye~“大”資料
- GOODGo
- Codeforces Good Bye 2017 C. New Year and Curling(運用數學解析幾何的知識判斷)Go
- A good PlayerGo
- good booksGo
- FolderCompareFrame with good layoutGo
- Some good websites for C++GoWebC++
- How Good Are Your Opinion 2Go
- Cheap ghd straighteners a goodAIGo
- How To Kill Good IdeasGoIdea
- Good documentation or books related to OracleGoOracle
- Good Links related OracleGoOracle
- Good story for dear friends.Go
- Number of k-good subarraysGo
- 2010//11/24 11.24 好友共享美食 Good Food, Good FriendsGo
- Good site on Oracle tech blogGoOracle
- 對maven的通俗理解,goodMavenGo
- Your Prediction Gets As Good As Your DataGo
- Ghd cheap good earthenware oneGo
- Good Coding Skills Are Not Enough (轉)Go
- learn english, a good website to learn englishGoWeb
- good wife真的很好看Go
- rember me all time good luckREMGo
- CF1762F Good PairsGoAI
- Bye Delphi!Borland要賣掉他的IDE業務了IDE
- 六年級數學期中考試只考了88分, 但試卷被老師寫下:Good! very good!! very very good!!!Go
- Good-Technology:2013年Q4企業移動裝置市場WP份額不足1%Go
- java繼承——對物件中的重複內容說ByeJava繼承物件
- This is a good question,初學者都犯暈!Go
- 1512. Number of Good PairsGoAI
- 一個RPC的demo(good)RPCGo
- Some good articles about SQL*loaderGoSQL
- All good things come to an endGo
- ABC 328F Good Set QueryGo