A - Maya Calendar
代码:
#include<bits/stdc++.h>
using namespace std;
char s1[20][10]={"pop","no","zip","zotz","tzec","xul","yoxkin","mol","chen","yax","zac","ceh","mac","kankin","muan","pax","koyab","cumhu","uayet"};
char s2[20][10]={"imix","ik","akbal","kan","chicchan","cimi","manik","lamat","muluk","ok","chuen","eb","ben","ix","mem","cib","caban","eznab","canac","ahau"};
int n,cur;
struct data{
int day;
char month[20];
int year;
}h,t;
int main(){
while(scanf("%d",&n)!=EOF){
cur = 0;
cout << n << endl;
while(n--){
cin >> h.day >> h.month >> h.year;
for(int i=0;i<19;i++){
if(strcmp(h.month,s1[i])==0)//比较两个字符串是否相等用strcmp,返回值为0,即相等
{
cur = h.year*365 + 20*i + h.day;//不必纠结最后一月与前几个月的区别,因为都是20*对应的月份减1
break;
}
}
if(t.year%260==0){
cout << "13 ahau " << t.year - 1 << endl;
}
else{
t.year = cur /260;
cur %= 260;
cout << cur%13+1 << " " << s2[cur%20] << " " << t.year << endl;
}
}
}
return 0;
}
B - Diplomatic License
题解
//求两点终点坐标
#include<iostream>
using namespace std;
struct Point{
long long x,y;
}first,last,now;
int n;
int main(){
while(scanf("%d",&n)!=EOF){
cout << n;
cin >> first.x >> first.y;
last = first;
for(int i=2;i<=n;i++){
cin >> now.x >> now.y;
printf(" %.6lf %.6lf",(last.x+now.x)/2.0,(last.y+now.y)/2.0);
last = now;
}
printf(" %.6lf %.6lf",(last.x+first.x)/2.0,(last.y+first.y)/2.0);
cout << endl;
}
}
C - “Accordian” Patience
主要是用数组模拟线性表
D - Broken Keyboard (a.k.a. Beiju Text)
题解
//用数组模拟存储链表 or STL
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
char s[N];
int main(){
while(~scanf("%s",s+1)){
int next[N] = {0};
int cur = 0,last = 0;
for(int i=1;s[i];i++){ //挨个遍历每个字符,直到s[i]不存在
if(s[i]=='[') cur = 0;
if(s[i]==']')cur = last;
else {//模拟链表的插入
next[i] = next[cur];
next[cur] = i;
if(cur == last) last = i;
cur = i;
}
}
for(int i = next[0];i!=0;i=next[i])
if(s[i]!='['&&s[i]!=']')
cout << s[i];
cout << endl;
}
return 0;
}
题目连接:https://vjudge.net/problem/UVA-11988
E - Satellites
题解
//
#include<bits/stdc++.h>
#include<cmath>//sin函数
using namespace std;
#define r 6440
double s,a,ad,cd;
char str[10];
int main(){
while(scanf("%d%d%s",&s,&a,str)!=EOF){
if(str[0]=='m'){
a = a / 60.0;
}
double angle = M_PI * a /180;
double arc = angle *(s+r);//表示圆弧距离
double dis = 2*(s+r)*sin(angle/2);//直线距离
if(a>180)arc = 2*M_PI*(s+r) - arc;
printf("%.6f%.6f\n",arc,dis);
}
}