1. 程式人生 > 其它 >1.19學習總結

1.19學習總結

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;
}