Milking Cows : 对输入的工作时间做排序处理,之后模拟工作过程,求出答案。。。
/*
ID: Jming
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_N = 5005;
int N;
struct node {
int a, b;
};
node Time[MAX_N];
bool Cmp(const node &n1, const node &n2) {
if (n1.a == n2.a) return n1.b < n2.b;
else return n1.a < n2.a;
}
int main()
{
freopen("milk2.in", "r", stdin);
freopen("milk2.out", "w", stdout);
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d %d", &Time[i].a, &Time[i].b);
}
sort(Time, Time+N, Cmp);
int mybegin = Time[0].a, myend = Time[0].b;
int work = myend - mybegin, no_work = 0;
for (int i = 1; i < N; ++i) {
if (Time[i].a <= myend) {
myend = max(myend, Time[i].b);
}else {
work = max(work, myend - mybegin);
no_work = max(no_work, Time[i].a - myend);
mybegin = Time[i].a, myend = Time[i].b;
}
}
work = max(work, myend - mybegin);
printf("%d %d\n", work, no_work);
return 0;
}
Transformations :将转换方法在纸上模拟一下,可发现规律,之后变成程序处理即可。。。
/*
ID: Jming
PROG: transform
LANG: C++
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX_N = 15;
char arr_str[MAX_N][MAX_N], t_arr_str[MAX_N][MAX_N], to_arr_str[MAX_N][MAX_N];
int N;
bool Judge(char str1[][15], char str2[][15]) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
if (str1[i][j] != str2[i][j]) {
return false;
}
}
}
return true;
}
void number1(char str1[][15], char str2[][15]) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
str1[j][N - 1 - i] = str2[i][j];
}
}
}
void number2(char str1[][15], char str2[][15]) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
str1[N - 1 - i][N - 1 - j] = str2[i][j];
}
}
}
void number3(char str1[][15], char str2[][15]) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
str1[N - 1 - j][i] = str2[i][j];
}
}
}
void number4(char str1[][15], char str2[][15]) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
str1[i][N - 1 - j] = str2[i][j];
}
}
}
void Solve() {
number1(t_arr_str, arr_str);
if (Judge(t_arr_str, to_arr_str)) {
printf("1\n");
return;
}
number2(t_arr_str, arr_str);
if (Judge(t_arr_str, to_arr_str)) {
printf("2\n");
return;
}
number3(t_arr_str, arr_str);
if (Judge(t_arr_str, to_arr_str)) {
printf("3\n");
return;
}
number4(t_arr_str, arr_str);
if (Judge(t_arr_str, to_arr_str)) {
printf("4\n");
return;
}
char arr_str1[MAX_N][MAX_N];
for (int i = 0; i < N; ++i) {
strcpy(arr_str1[i], t_arr_str[i]);
}
number1(t_arr_str, arr_str1);
if (Judge(t_arr_str, to_arr_str)) {
printf("5\n");
return;
}
number2(t_arr_str, arr_str1);
if (Judge(t_arr_str, to_arr_str)) {
printf("5\n");
return;
}
number3(t_arr_str, arr_str1);
if (Judge(t_arr_str, to_arr_str)) {
printf("5\n");
return;
}
if (Judge(t_arr_str, to_arr_str)) {
printf("6\n");
return;
}
printf("7\n");
}
int main()
{
freopen("transform.in", "r", stdin);
freopen("transform.out", "w", stdout);
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%s", arr_str[i]);
strcpy(t_arr_str[i], arr_str[i]);
}
for (int i = 0; i < N; ++i) {
scanf("%s", to_arr_str[i]);
}
Solve();
return 0;
}
Name That Number :字典树 + Dfs (解法同 hdu 1298 解题报告点击此处)
/*
ID: Jming
PROG: namenum
LANG: C++
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstring>
#include <map>
using namespace std;
const int MAX = 26;
map<int, string> myMap;
bool ansJudge;
struct Trie{
bool Judge;
Trie* next[MAX];
Trie() {
Judge = false;
memset(next, NULL, sizeof(next));
}
};
Trie* Root;
void CreTrie(string str) {
int len = str.size();
Trie* p = Root;
for (int i = 0; i < len; ++i) {
int pos = str[i] - 'A';
if (!(p->next[pos])) {
p->next[pos] = new Trie;
}
p = p->next[pos];
}
p->Judge = true;
}
void DelTrie(Trie* T) {
for (int i = 0; i < MAX; ++i) {
if (T->next[i]) {
DelTrie(T->next[i]);
}
}
delete[] T;
}
void Ini() {
ifstream fcin("dict.txt");
if (!fcin) {
system("pause");
}
string str;
while (fcin >> str) {
CreTrie(str);
}
myMap[2] = "ABC"; myMap[3] = "DEF"; myMap[4] = "GHI"; myMap[5] = "JKL";
myMap[6] = "MNO"; myMap[7] = "PRS"; myMap[8] = "TUV"; myMap[9] = "WXY";
}
void Dfs(string str, int pos, Trie* T, string ansStr) {
for (int i = 0; i < 3; ++i) {
Trie* t_Trie = T->next[myMap[str[pos] - '0'][i] - 'A'];
if (t_Trie) {
if ((t_Trie->Judge) && (pos == (str.size() - 1))) {
if (!ansJudge) ansJudge = true;
cout << ansStr + myMap[str[pos] - '0'][i] << endl;
}
else Dfs(str, pos + 1, t_Trie, ansStr + myMap[str[pos] - '0'][i]);
}
}
}
int main()
{
Root = new Trie;
ansJudge = false;
Ini();
freopen("namenum.in", "r", stdin);
freopen("namenum.out", "w", stdout);
string str;
cin >> str;
Dfs(str, 0, Root, "");
if (!ansJudge) {
cout << "NONE" << endl;
}
DelTrie(Root);
return 0;
}
Palindromic Squares :进制处理。。。
/*
ID: Jming
PROG: palsquare
LANG: C++
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;
int base;
struct myNode {
int number;
int square;
}node[305];
void Init() {
for (int i = 1; i <= 300; ++i) {
node[i - 1].number = i;
node[i - 1].square = i * i;
}
}
char judgeChar(int tmp) {
if (tmp >= 0 && tmp <= 9) return ('0' + tmp);
else return ('A' + (tmp - 10));
}
string getNum(int x) {
string str = "";
while (x >= base) {
int tmp = x%base;
x /= base;
str = judgeChar(tmp) + str;
}
return (judgeChar(x) + str);
}
bool judgePalindromic(string str) {
int myBegin = 0, myEnd = str.size() - 1, myCount = str.size() >> 1;
for (int i = 0; i < myCount; ++i) {
if (str[myBegin + i] != str[myEnd - i]) {
return false;
}
}
return true;
}
void Solve() {
for (int i = 0; i < 300; ++i) {
string str = getNum(node[i].square);
if (judgePalindromic(str)) {
cout << (getNum(node[i].number)) << " " << str << endl;
}
}
}
int main()
{
freopen("palsquare.in", "r", stdin);
freopen("palsquare.out", "w", stdout);
Init();
scanf("%d", &base);
Solve();
return 0;
}
Dual Palindromes :进制处理。。。
/*
ID: Jming
PROG: dualpal
LANG: C++
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
using namespace std;
int base, N, S;
string getNum(int x) {
string str = "";
while (x >= base) {
int tmp = x%base;
x /= base;
str = (char)('0' + tmp) + str;
}
return ((char)('0' + x) + str);
}
bool judgePalindromic(string str) {
int myBegin = 0, myEnd = str.size() - 1, myCount = str.size() >> 1;
for (int i = 0; i < myCount; ++i) {
if (str[myBegin + i] != str[myEnd - i]) {
return false;
}
}
return true;
}
void Solve() {
int myCount = 1;
while (myCount <= N) {
++S;
int sum = 0;
for (base = 2; base <= 10; ++base) {
string str = getNum(S);
if (judgePalindromic(str)) {
++sum;
if (sum >= 2) break;
}
}
if (sum >= 2) {
printf("%d\n", S);
++myCount;
}
}
}
int main()
{
freopen("dualpal.in", "r", stdin);
freopen("dualpal.out", "w", stdout);
scanf("%d %d", &N, &S);
Solve();
return 0;
}