灵动ICPC冬令营基础-2

A- Maya Calendar

注意两个纪年法一个是从0开始,一个是从1开始。

#include<stdio.h>
#include<string.h>
int main(){
    char a[][10]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"};
    char b[][10]={"imix","ik","akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"};
	int current,NumberOfTheDay,Year,Number,Year1,NameOfTheDay;
	char Month[10];
	int n,i;
	scanf("%d",&n);
	printf("%d\n",n);
	while(n--){
		current=0;
		scanf("%d. %s %d",&NumberOfTheDay,Month,&Year);
	    for(i=0;i<19;i++){
	    	if((strcmp(Month,a[i]))==0){
	    		 current=current+i*20;
			}
		}
		current+=Year*365;
		current+=NumberOfTheDay+1;
		if(current%260==0) Year1=current/260-1,Number=13,NameOfTheDay=20;
		else{
			Year1=current/260;
			Number=(current % 13 == 0 ? 13 : current% 13);
			NameOfTheDay=(current % 20 == 0 ? 20 : current% 20)-1;
		}
		printf("%d %s %d\n",Number,b[NameOfTheDay],Year1);
	}
	return 0;
}

B - Diplomatic License

找一个不断改变的now来更新当前的点坐标和它的下一个。

#include <cstdio>
#include <cmath>
#include <algorithm>
const int N = 100008;
struct Cord{
	long long x, y;
}loc[N];
int main() {
	int  i, j, n;
	double avex, avey;
	while(~scanf("%d", &n)) {
		printf("%d ", n);
		for (i = 1; i <n; i++)
			scanf("%lld %lld", &loc[i].x, &loc[i].y);
			avex=(loc[i].x+loc[i+1].x)/2;
			avey=(loc[i].y+loc[i+1].y)/2;
			printf("%6lf %6lf ", avex, avey);
		}
		scanf("%lld %lld", &loc[n].x, &loc[n].y);
		avex=(loc[n].x+loc[1].x)/2;
		avey=(loc[n].y+loc[1].y)/2;
		printf("%6lf %6lf", avex, avey);
		puts("");
	}
	
	return 0;
}

C - “Accordian” Patience

太难了就放题目吧。

You are to simulate the playing of games of ``Accordian’’ patience, the rules for which are as follows:

Deal cards one by one in a row from left to right, not overlapping. Whenever the card matches its immediate neighbour on the left, or matches the third card to the left, it may be moved onto that card. Cards match if they are of the same suit or same rank. After making a move, look to see if it has made additional moves possible. Only the top card of each pile may be moved at any given time. Gaps between piles should be closed up as soon as they appear by moving all piles on the right of the gap one position to the left. Deal out the whole pack, combining cards towards the left whenever possible. The game is won if the pack is reduced to a single pile.
Situations can arise where more than one play is possible. Where two cards may be moved, you should adopt the strategy of always moving the leftmost card possible. Where a card may be moved either one position to the left or three positions to the left, move it three positions.
Input
Input data to the program specifies the order in which cards are dealt from the pack. The input contains pairs of lines, each line containing 26 cards separated by single space characters. The final line of the input file contains a # as its first character. Cards are represented as a two character code. The first character is the face-value (A=Ace, 2-9, T=10, J=Jack, Q=Queen, K=King) and the second character is the suit (C=Clubs, D=Diamonds, H=Hearts, S=Spades).
Output
One line of output must be produced for each pair of lines (that between them describe a pack of 52 cards) in the input. Each line of output shows the number of cards in each of the piles remaining after playing ``Accordian patience’’ with the pack of cards as described by the corresponding pairs of input lines.

D - Broken Keyboard (a.k.a. Beiju Text)

要是用指针有点复杂,可以用数组来模拟指针的作用。

#include<cstdio>
#define maxl 100007
int main(){
    char s[maxl];
	while(~scanf("%s",s+1)){
		int cur=0, last =0;
		int next[maxl]={0};
		for(int i=1;s[i];i++){
			if(s[i]=='[') cur=0;
			else 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])  printf("%c",s[i]);
		printf("\n");
	}
	return 0;
}

E - Satellites

简单的高中圆的计算,会公式就行了,就是要注意简化不然容易超时。

#include<cstdio>
#include<cmath>
const double r=6440;
int main (){
   double h,R,a;
   char s[10];
   while((scanf("%lf%lf%s",&h,&a,s))!=EOF){
   	if(s[0]=='m')  a=a/60;
   	R=r+h;
   	double A = M_PI*a/180;
   	double arc = A*R;
   	double chord = 2*R*sin(A/2);
   	if(a>180) arc=2*M_PI*R-arc;
   	printf("%.6lf %.6lf\n",arc,chord);
   }
   
   
   return 0;
} 

F - Fourth Point !!

先设定b与c相同,若不同再用swap函数交换成c与b相同,然后就带公式了。

#include<iostream>
using namespace std;
struct point {
	double x,y;
}a,b,c,d,e;
int main(){
	while(~scanf("%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y))
	{
		scanf("%lf%lf%lf%lf",&c.x,&c.y,&d.x,&d.y);
		if(a.x==c.x&&a.y==c.y) swap(a,b);
		if(a.x==d.x&&a.y==d.y) swap(a,b),swap(c,d);
		if(b.x==d.x&&b.y==d.y) swap(c,d);
		if(a.x==b.x&&a.y==b.y) swap(a,c);
		e.x=a.x+d.x-c.x,e.y=a.y+d.y-c.y;
		printf("%.3lf %.3lf\n",e.x,e.y);
	}
	return 0;
}

G - The Circumference of the Circle

公式很多,可以用函数一个个的编写公式。

#include<cstdio>
#include<cmath> 
#define pi 3.141592653589793
double s(double a ,double b ,double c)
{
	double p,D;
	p=(a+b+c)/2;
	 D=sqrt(p*(p-a)*(p-b)*(p-c));
	 return D;
}
double l(double x,double y,double x1,double y1)
{
	double L;
	 L=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
	 return L;
}
double r(double a,double b,double c,double s)
{
	double R;
	R=a*b*c/2/s;
	return R;
}
int main(){
	double a,b,c,x1,x2,x3,y1,y2,y3,x,d;
	while((scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3))!=EOF)
	{
		a=l(x1,y1,x2,y2);
		b=l(x1,y1,x3,y3);
		c=l(x2,y2,x3,y3);
		x=s(a,b,c);
		d=r(a,b,c,x);
		printf("%.2lf\n",d*pi);
	}
	return 0;
}

H - Titanic

输入有点烦,还要判断东南西北来决定坐标的正负接下来就是带公式了。

#include<cstdio>
#include<cmath>
char s[20];
const double r = 6875 / 2.0, pi = atan(1.0) * 4;
int main()
{
    int x, b, c;
    scanf("%s%s%s%s%s%s%s%s%s%d^%d\'%d\"%s", s, s, s, s, s, s, s, s, s, &x, &b, &c, s);
    double y1 = (x + b / 60.0 + c / 3600.0)*(s[0] == 'N' ? 1 : -1) / 180 * pi;
    scanf("%s%d^%d'%d\"%s", s, &x, &b, &c, s);
    double x1 = (x + b / 60.0 + c / 3600.0)*(s[0] == 'E' ? 1 : -1) / 180 * pi;
    scanf("%s%s%s%s%s%d^%d'%d\"%s", s, s, s, s, s, &x, &b, &c, s);
    double y2 = (x + b / 60.0 + c / 3600.0)*(s[0] == 'N' ? 1 : -1) / 180 * pi;
    scanf("%s%d^%d'%d\"%s", s, &x, &b, &c, s);
    double x2 = (x + b / 60.0 + c / 3600.0)*(s[0] == 'E' ? 1 : -1) / 180 * pi;
    double dis = r*acos(cos(y1)*cos(y2)*cos(x2 - x1) + sin(y1)*sin(y2));
    scanf("%s", s);
    printf("The distance to the iceberg: %.2lf miles.\n%s", dis, dis + 0.005 - 100 < 0.0001 ? "DANGER!\n" : "");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值