250分:
简单题,判断C A T这三个字符的个数就行了
/*************************************************************************
> File Name: 250.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年05月08日 星期五 20时29分05秒
************************************************************************/
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
class TaroString {
public:
string getAnswer(string str) {
int n = str.length();
int cnt1 = 0, cnt2 = 0, cnt3 = 0;
int pos1 = 0, pos2 = 0, pos3 = 0;
for (int i = 0; i < n; ++i) {
if (str[i] == 'C') {
++cnt1;
pos1 = i;
}
else if (str[i] == 'A') {
++cnt2;
pos2 = i;
}
else if (str[i] == 'T') {
++cnt3;
pos3 = i;
}
}
if (cnt1 != 1 || cnt2 != 1 || cnt3 != 1) {
return "Impossible";
}
if (pos1 < pos2 && pos2 < pos3) {
return "Possible";
}
return "Impossible";
}
};
500分:
暴力枚举最左端,然后求最小的右端
全部向左和全部向右的也要考虑
/*************************************************************************
> File Name: 500.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年05月08日 星期五 20时37分19秒
************************************************************************/
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> Pint;
class TaroFriends {
public:
int getNumber(vector <int> arr, int X) {
int n = arr.size();
if (n == 1) {
return 0;
}
int l, r;
int ans = (1 << 30);
for (int i = 0; i < n; ++i) {
for (int sgn = 0; sgn < 2; ++sgn) {
l = arr[i];
if (sgn) {
l += X;
}
else {
l -= X;
}
r = -(1 << 30);
for (int j = 0; j < n; ++j) {
if (j == i) {
continue;
}
if (arr[j] - X < l && arr[j] + X < l) {
r = -(1 << 30);
break;
}
if (arr[j] - X < l) {
r = max(r, arr[j] + X);
}
else {
r = max(r, arr[j] - X);
}
}
if (r == -(1 << 30)) {
continue;
}
ans = min(ans, r - l);
}
}
return ans;
}
};
1000分:
dp[i][sta][k]表示枚举到第i张卡,<=10的数字状态为sta,共有k个不同的数字的方案数,转移分第i张卡取或者不取
/*************************************************************************
> File Name: 1000.cpp
> Author: ALex
> Mail: zchao1995@gmail.com
> Created Time: 2015年05月08日 星期五 21时25分26秒
************************************************************************/
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>
using namespace std;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;
LL dp[55][1100][110];
class TaroCards {
public:
LL getNumber(vector <int> F, vector <int> S, int K) {
int n = F.size();
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < (1 << 10); ++j) {
for (int k = 0; k <= K; ++k) {
dp[i][j][k] = 0;
}
}
}
dp[0][0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < (1 << 10); ++j) {
for (int k = 0; k <= K; ++k) {
if (dp[i][j][k]) {
dp[i + 1][j][k] += dp[i][j][k];
int newsta = j;
int kk = k;
if (F[i] > 10) {
++kk;
}
else if (!((1 << (F[i] - 1)) & newsta)) {
++kk;
newsta |= (1 << ((F[i] - 1)));
}
if (!((1 << (S[i] - 1)) & newsta)) {
++kk;
newsta |= (1 << ((S[i] - 1)));
}
if (kk > K) {
continue;
}
dp[i + 1][newsta][kk] += dp[i][j][k];
}
}
}
}
LL ans = 0;
for (int i = 0; i < (1 << 10); ++i) {
for (int j = 0; j <= K; ++j) {
ans += dp[n][i][j];
}
}
return ans;
}
};