Problem Id | Title | |
Problem A | A+B | |
Problem B | 统计字数 | |
Problem C | 生日计算 | |
Problem D | 冬瓜的寒假之旅 |
Problem A(略)
Problem B
B题目就是一个统计字符的简单模拟,纵向记录横向输出就可。先for一圈遍历遍最大的个数可确定高度。
/****************************************/
/***** Desgard_Duan *****/
/****************************************/
//#pragma comment(linker, "/STACK:102400000,102400000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> using namespace std; vector<string> ans;
int let[]; int main () {
string text = "", in;
for (int i = ; i < ; ++ i) {
getline(cin, in);
text += in;
}
//cout << text << endl;
memset (let, , sizeof (let));
int Max = ;
for (int i = ; i < text.size(); ++ i) {
if (isalpha(text[i])) {
let[text[i] - 'A'] ++;
Max = max (Max, let[text[i] - 'A']);
}
}
for (int i = ; i <= Max; ++ i) {
string text_line = "";
for (int j = ; j < ; ++ j) {
if (i > Max - let[j]) {
text_line += "*";
} else {
text_line += " ";
}
if (j != ) text_line += " ";
}
cout << text_line << endl;
}
puts("A B C D E F G H I J K L M N O P Q R S T U V W X Y Z");
return ;
}
Problem C
考虑闰年的2月29日生日就可,其他没有什么坑。
/****************************************/
/***** Desgard_Duan *****/
/****************************************/
//#pragma comment(linker, "/STACK:102400000,102400000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <cmath>
#include <numeric> using namespace std; int judge( int x ) {
if( x % == || ( x % == && x % != ) )
return ;
return ;
}
int main() {
int y, m, d, t;
while(scanf( "%d", &t ) != EOF) {
while( t-- ) {
scanf( "%d-%d-%d", &y, &m, &d );
int sum = ;
if( judge( y ) && m == && d == && !judge( y + ) ) {
puts( "-1" );
continue;
}
for( int i = ; i <= ; ++i )
if(judge( y + i ))
sum ++;
if( judge( y + ) && m <= && d < )
--sum;
if( judge( y ) && m >= )
--sum;
printf( "%d\n", sum + * );
}
}
return ;
}
Problem D
主要考察枚举法。即全排列。在数据量不大的情况下,即可将TSP问题的所有情况全部列出,寻求最佳值。
另外可以学习一下next_permutation函数的用法,白书中也有介绍。
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue> using namespace std; int per[]; struct point {
double x, y;
} p[]; double dis(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
} int main() {
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T, n, cas = ;
double ans;
bool f;
scanf("%d", &T);
while(T--) {
f = true;
scanf("%d", &n);
for(int i = ; i <= n; ++i) {
scanf("%lf%lf", &p[i].x, &p[i].y);
}
for(int i = ; i <= n; ++i) {
per[i - ] = i;
}
do {
point tmp;
tmp.x = ;
tmp.y = ;
double sum = dis(tmp, p[per[]]);
for(int i = ; i < n; ++i) {
sum += dis(p[per[i]], p[per[i - ]]);
}
sum += dis(tmp, p[per[n - ]]);
if(f) {
ans = sum;
f = false;
} else
ans = min(ans, sum);
} while(next_permutation(per, per + n));
printf("Case #%d: %.2lf\n", cas++, ans);
}
return ;
}