2021.1.19上海冬令营day2

2.1指针

直接转载一个还不错的博客指针详解

2.2链表

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.3计算几何

1分(’)等于1/60度(°)
角度转弧度 π/180×角度
弧度变角度 180/π×弧度
PI=acos(-1.0);
弧度乘半径等于弧长
在这里插入图片描述
已知三点求外接圆直径:
三点所构成三角形任意两边的乘积除以第三条边上的高等于其外接圆直径。
已知三条边求三角形面积:
海伦公式:S=√[p(p-a)(p-b)(p-c)]
p=(a+b+c)/2
已知两点经纬度求球面最短距离公式:
A,B两点,w代表纬度,j代表经度
A,B两点,w代表纬度,j代表经度
转载一个带推导的网站传送门

当天题目:

A - Maya Calendar POJ - 1008
During his last sabbatical, professor M. A. Ya made a surprising discovery about the old Maya calendar. From an old knotted message, professor discovered that the Maya civilization used a 365 day long year, called Haab, which had 19 months. Each of the first 18 months was 20 days long, and the names of the months were pop, no, zip, zotz, tzec, xul, yoxkin, mol, chen, yax, zac, ceh, mac, kankin, muan, pax, koyab, cumhu. Instead of having names, the days of the months were denoted by numbers starting from 0 to 19. The last month of Haab was called uayet and had 5 days denoted by numbers 0, 1, 2, 3, 4. The Maya believed that this month was unlucky, the court of justice was not in session, the trade stopped, people did not even sweep the floor.

For religious purposes, the Maya used another calendar in which the year was called Tzolkin (holly year). The year was divided into thirteen periods, each 20 days long. Each day was denoted by a pair consisting of a number and the name of the day. They used 20 names: imix, ik, akbal, kan, chicchan, cimi, manik, lamat, muluk, ok, chuen, eb, ben, ix, mem, cib, caban, eznab, canac, ahau and 13 numbers; both in cycles.

Notice that each day has an unambiguous description. For example, at the beginning of the year the days were described as follows:

1 imix, 2 ik, 3 akbal, 4 kan, 5 chicchan, 6 cimi, 7 manik, 8 lamat, 9 muluk, 10 ok, 11 chuen, 12 eb, 13 ben, 1 ix, 2 mem, 3 cib, 4 caban, 5 eznab, 6 canac, 7 ahau, and again in the next period 8 imix, 9 ik, 10 akbal . . .

Years (both Haab and Tzolkin) were denoted by numbers 0, 1, : : : , where the number 0 was the beginning of the world. Thus, the first day was:

Haab: 0. pop 0

Tzolkin: 1 imix 0
Help professor M. A. Ya and write a program for him to convert the dates from the Haab calendar to the Tzolkin calendar.
Input
The date in Haab is given in the following format:
NumberOfTheDay. Month Year

The first line of the input file contains the number of the input dates in the file. The next n lines contain n dates in the Haab calendar format, each in separate line. The year is smaller then 5000.
Output
The date in Tzolkin should be in the following format:
Number NameOfTheDay Year

The first line of the output file contains the number of the output dates. In the next n lines, there are dates in the Tzolkin calendar format, in the order corresponding to the input dates.
Sample Input
3
10. zac 0
0. pop 0
10. zac 1995
Sample Output
3
3 chuen 0
1 imix 0
9 cimi 2801
题意:根据要求将日历转换
代码:

#include<cstdio>
#include<iostream>
#include<cstring>
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 main()
{
    int t,day,num,year,ans;
    char mon[10];
    cin>>t;
    cout<<t<<endl;
    while(t--)
    {
        ans=0;
      scanf("%d. %s %d",&day,mon,&year);
        for(int i=0; i<20; i++)
        {
            if(strcmp(s1[i],mon)==0)
            {
                ans=year*365+day+20*i;
                break;
            }
        }
        ans++;
        year=ans/260;
        num=ans%260;
        if(num==0)
        {
            year--;
            num+=260;

        }
        day=num%13;
        if(day==0) day=13;
        int mon=num%20;
        if(mon==0) mon=20;
        cout<<day<<" "<<s2[mon-1]<<" "<<year<<endl;
    }
    return 0;
}

B - Diplomatic License POJ - 1939
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<cstdio>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        double iX, iY;
        double preX, preY;
        double x,y;
        for(int i=0; i<n; i++)
        {
            cin>>x>>y;
            if(i==0)
            {
                iX=x;
                iY=y;
                preX=x;
                preY=y;
                cout<<n;
            }
            else
            {
                printf(" %0.6f %0.6f", preX+(x-preX)/2.0, preY+(y-preY)/2.0);
                preX=x;
                preY=y;
            }
        }
        printf(" %0.6f %0.6f\n",iX+(x-iX)/2.0, iY+(y-iY)/2.0);
    }
    return 0;
}

C - “Accordian” Patience POJ - 1214
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

还未补

D - Broken Keyboard (a.k.a. Beiju Text) UVA - 11988
在这里插入图片描述
题意:遇到【光标就到文字最前面,遇到】光标就到最后面,求最后输出的样子
思路:两个队列,但超时了。
搬运ac代码:

#include <iostream>
#include<string.h>
#include <algorithm>
using namespace std;
const int maxn = 100000 + 5;
 
char buf[maxn];
int Next[maxn];
 
int main(){
    int cur, last,n;
    while (scanf("%s", buf+1)!=EOF){
        n = strlen(buf + 1);
        cur = last = 0;
        for (int i = 1; i <= n; i++){
            if (buf[i] == '[')cur = 0;    //house键
            else if (buf[i] == ']')cur = last; //end键
            else{
                Next[i] = Next[cur];   //字符i的下一个位置为cur的下一个位置
                Next[cur] = i;         //curr的下一个位置为i
                //更新cur和last
                if (cur == last)last = i;   //cur等于i表示光标在显示屏最后一个字符
                cur = i;  //移动光标
            }
        }
        Next[last] = 0;  //结束位置
        for (int i = Next[0]; i != 0; i = Next[i])
            printf("%c", buf[i]);
        printf("\n");
    }
    return 0;
}

E - Satellites UVA - 10221
在这里插入图片描述
题意:给夹角,求弦长和弧长
思路:单位转换,弄懂公式,还有大于180的角用360减一下
代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
 double s,a;
 char c[100];
 while(~scanf("%lf %lf %s",&s,&a,c))
 {
     if(strcmp(c,"min")==0) a/=60;
     if(a>180) a=360-a;
     double an=a*acos(-1.0)/180.0;
     double hu=2.0*(s+6440)*sin(an/2.0);
     double xian=an*(s+6440);
     printf("%.6f %.6f\n",xian,hu);
 }
    return 0;
}

F - Fourth Point !! UVA - 10242
在这里插入图片描述
题意:给四个点,是平行四边形相邻两边的坐标(无序),求第四个点的坐标
思路:画图想好所有情况,一一写出
代码:

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
   double a[100];
   double x,y;
   while(cin>>a[1])
   {
       for(int i=2;i<=8;i++)
       {
           cin>>a[i];
       }
       if(a[1]==a[5]&&a[2]==a[6])
       {
           x=a[3]+a[7]-a[1];
           y=a[4]+a[8]-a[2];
       }
       else if(a[3]==a[7]&&a[4]==a[8])
       {
           x=a[1]+a[5]-a[3];
            y=a[2]+a[6]-a[4];
       }
       else if(a[1]==a[7]&&a[2]==a[8])
       {
            x=a[3]+a[5]-a[1];
            y=a[4]+a[6]-a[2];
       }
       else if(a[3]==a[5]&&a[4]==a[6])
       {
           x=a[1]+a[7]-a[3];
            y=a[2]+a[8]-a[4];
       }
       printf("%.3f %.3f\n",x,y);
   }
    return 0;
}

G - The Circumference of the Circle POJ - 2242
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
Sample Output
3.14
4.44
6.28
31.42
62.83
632.24
3141592.65
题意:已知三点,求外接圆周长
思路:数学性质见本文知识点区域
代码:

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

H - Titanic POJ - 2354
It is a historical fact that during the legendary voyage of “Titanic” the wireless telegraph machine had delivered 6 warnings about the danger of icebergs. Each of the telegraph messages described the point where an iceberg had been noticed. The first five warnings were transferred to the captain of the ship. The sixth one came late at night and a telegraph operator did not notice that the coordinates mentioned were very close to the current ship’s position.

Write a program that will warn the operator about the danger of icebergs!

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
题意:给两点经纬度求距离
思路:输入比较费劲,其他的一套公式即可,公式以及介绍推导的链接在前面知识点处给出
代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
char s[100010];
char c;
int f;
double r=6875/2.0;
int main()
{
    scanf("%*s%*s");
	scanf("%*s%*s%*s");
	scanf("%*s%*s%*s%*s");
    int a,b,c;
    scanf("%d^%d\'%d\"",&a,&b,&c);
    cin>>s;
    if(s[0]=='N') f=1;
    else f=-1;
    double wa=(a+b/60.0+c/3600.0)*f/180*acos(-1.0);
   scanf("%*s%d^%d\'%d\"",&a,&b,&c);
    cin>>s;
    if(s[0]=='E') f=1;
    else f=-1;
    double ja=(a+b/60.0+c/3600.0)*f/180*acos(-1.0);
   scanf("%*s%*s%*s%*s%*s");
    scanf("%d^%d\'%d\"",&a,&b,&c);
    cin>>s;
    if(s[0]=='N') f=1;
    else f=-1;
    double wb=(a+b/60.0+c/3600.0)*f/180*acos(-1.0);
    scanf("%*s%d^%d\'%d\"",&a,&b,&c);
    cin>>s;
    if(s[0]=='E') f=1;
    else f=-1;
    double jb=(a+b/60.0+c/3600.0)*f/180*acos(-1.0);
    cin>>s;
    double dis=r*acos(cos(wa)*cos(wb)*cos(jb-ja)+sin(wb)*sin(wa));
    printf("The distance to the iceberg: %.2f miles.\n",dis);
    if(dis+0.005<100) printf("DANGER!\n");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值