冬令营Day2

第一题:“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.
Sample Input

QD AD 8H 5S 3H 5H TC 4D JH KS 6H 8S JS AC AS 8D 2H QS TS 3S AH 4H TH TD 3C 6S
8C 7D 4C 4S 7S 9H 7C 5D 2S KD 2D QH JD 6D 9D JC 2C KH 3D QC 6C 9S KC 7H 9C 5C
AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD 2D 3D 4D 5D 6D 7D 8D TD 9D JD QD KD
AH 2H 3H 4H 5H 6H 7H 8H 9H KH 6S QH TH AS 2S 3S 4S 5S JH 7S 8S 9S TS JS QS KS
#

Sample Output

6 piles remaining: 40 8 1 1 1 1
1 piles remaining: 52

题解:

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

第二题 Diplomatic License

题干
In an effort to minimize the expenses for foreign affairs the countries of the world have argued as follows. It is not enough that each country maintains diplomatic relations with at most one other country, for then, since there are more than two countries in the world, some countries cannot communicate with each other through (a chain of) diplomats.

Now, let us assume that each country maintains diplomatic relations with at most two other countries. It is an unwritten diplomatic "must be" issue that every country is treated in an equal fashion. It follows that each country maintains diplomatic relations with exactly two other countries.

International topologists have proposed a structure that fits these needs. They will arrange the countries to form a circle and let each country have diplomatic relations with its left and right neighbours. In the real world, the Foreign Office is located in every country's capital. For simplicity, let us assume that its location is given as a point in a two-dimensional plane. If you connect the Foreign Offices of the diplomatically related countries by a straight line, the result is a polygon.

It is now necessary to establish locations for bilateral diplomatic meetings. Again, for diplomatic reasons, it is necessary that both diplomats will have to travel equal distances to the location. For efficiency reasons, the travel distance should be minimized. Get ready for your task!

Input
The input contains several testcases. Each starts with the number n of countries involved. You may assume that n>=3 is an odd number. Then follow n pairs of x- and y-coordinates denoting the locations of the Foreign Offices. The coordinates of the Foreign Offices are integer numbers whose absolute value is less than 1012. The countries are arranged in the same order as they appear in the input. Additionally, the first country is a neighbour of the last country in the list.
Output
For each test case output the number of meeting locations (=n) followed by the x- and y-coordinates of the locations. The order of the meeting locations should be the same as specified by the input order. Start with the meeting locations for the first two countries up to the last two countries. Finally output the meeting location for the n-th and the first country.
Sample Input

5 10 2 18 2 22 6 14 18 10 18
3 -4 6 -2 4 -2 6
3 -8 12 4 8 6 12

Sample Output

5 14.000000 2.000000 20.000000 4.000000 18.000000 12.000000 12.000000 18.000000 10.000000 10.000000
3 -3.000000 5.000000 -2.000000 5.000000 -3.000000 6.000000
3 -2.000000 10.000000 5.000000 10.000000 -1.000000 12.000000

Hint
Note that the output can be interpreted as a polygon as well. The relationship between the sample input and output polygons is illustrated in the figure on the page of Problem 1940. To generate further sample input you may use your solution to that problem.
题解

#include <iostream>
#include <iomanip>
#define F fixed
#define S setprecision(6)
#define max 1000
using namespace std;
double x[max],y[max];
int n,i;
    double pos1,pos2;
int main(){  
    while(scanf("%d",&n)!=EOF){
        printf("%d",n);
        for(i=0;i<n;i++){
            cin>>x[i]>>y[i];
        }
        for(i=0;i<n-1;i++){
            pos1 =(x[i]+x[i+1])/2.0;
            pos2 =(y[i]+y[i+1])/2.0;
            cout<<" "<<F<<S<<pos1<<F<<S<<" "<<pos2;
        }
        pos1 = (x[n-1]+x[0])/2.0;
        pos2 = (y[n-1]+y[0])/2.0;
        cout<<" "<<F<<S<<pos1<<" "<<F<<S<<pos2<<endl;
    }
    return 0;
}

第三题 Broken Keyboard (a.k.a. Beiju Text)

题干
You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed (internally).
You’re not aware of this issue, since you’re focusing on the text and did not even turn on the monitor! After you finished typing, you can see a text on the screen (if you turn on the monitor).
In Chinese, we can call it Beiju. Your task is to find the Beiju text.
Input

There are several test cases. Each test case is a single line containing at least one and at most 100,000
letters, underscores and two special characters ‘[’ and ‘]’. ‘[’ means the “Home” key is pressed
internally, and ‘]’ means the “End” key is pressed internally. The input is terminated by end-of-file
(EOF).
Output

For each case, print the Beiju text on the screen.
Sample Input

This_is_a_[Beiju]_text
[[]][][]Happy_Birthday_to_Tsinghua_University
Sample Output

BeijuThis_is_a__text
Happy_Birthday_to_Tsinghua_University
题解

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<float.h> 
#include<string.h>
#include<algorithm>
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
char s[100005];
int NEXT[100005],last,cur;
int main()
{
	int n,last,cur;

	while(scanf("%s",s+1)!=EOF)
	{
		 n=strlen(s+1);
		last=cur=0;
		NEXT[0]=0;
		for(int i=1;i<=n;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;
}

第四题 Fourth Point !!

题干
Description
Given are the (x,y) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the (x,y) coordinates of the fourth point.

Input
Each line of input contains eight floating point numbers: the (x,y) coordinates of one of the endpoints of the first side followed by the (x,y) coordinates of the other endpoint of the first side, followed by the (x,y) coordinates of one of the endpoints of the second side followed by the (x,y) coordinates of the other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates are between -10000 and +10000.

Output
For each line of input, print the (x,y) coordinates of the fourth point of the parallelogram in meters, to the nearest mm, separated by a single space.

Sample Input

0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000
1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000
1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145

Sample Output

1.000 0.000
-2.500 -2.500
0.151 -0.398
题解:

#include<iostream>
 using namespace std;
double s[8];
void change()
{
	double temp;
	if(s[0]==s[4]&&s[1]==s[5])
	{
		temp=s[0],s[0]=s[2],s[2]=temp;
		temp=s[1],s[1]=s[3],s[3]=temp;
	}
	else if(s[0]==s[6]&&s[1]==s[7])
	{
		temp=s[0],s[0]=s[2],s[2]=temp;
		temp=s[1],s[1]=s[3],s[3]=temp;
		temp=s[4],s[4]=s[6],s[6]=temp;
		temp=s[5],s[5]=s[7],s[7]=temp;
	}
	else if(s[2]==s[6]&&s[3]==s[7])
	{
		temp=s[4],s[4]=s[6],s[6]=temp;
		temp=s[5],s[5]=s[7],s[7]=temp;
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",s,s+1,s+2,s+3,s+4,s+5,s+6,s+7))
	{
		change();
		double ansx,ansy;
		ansx=s[6]+(s[0]-s[2]);
		ansy=s[7]+(s[1]-s[3]);
		printf("%.3lf %.3lf\n",ansx,ansy);
	}
	return 0;
}

第五题:The Circumference of the Circle
题干:
To calculate the circumference of a circle seems to be an easy task - provided you know its diameter. But what if you don’t?

You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.

Input
The input will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.
Output
For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.
Sample Input

0.0 -0.5 0.5 0.0 0.0 0.5
0.0 0.0 0.0 1.0 1.0 1.0
5.0 5.0 5.0 7.0 4.0 6.0
0.0 0.0 -1.0 7.0 7.0 7.0
50.0 50.0 50.0 70.0 40.0 60.0
0.0 0.0 10.0 0.0 20.0 1.0
0.0 -500000.0 500000.0 0.0 0.0 500000.0

题解:

#include<iostream>
#include<cstdio>
#include<cmath>
#define Pi 3.141592653589793
using namespace std;
 
int main()
{
	double x1,x2,x3,y1,y2,y3;
	double l1,l2,l3;
	double p,h,d;
	while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
	{
		l1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		l2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
		l3=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
		p=(l1+l2+l3)/2;
		h=sqrt(p*(p-l1)*(p-l2)*(p-l3))*2/l3;
		d=l1*l2/h;
		printf("%.2lf\n",Pi*d);
	}
	return 0;
}

*别问其他题没有,问就是不会。 *

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值