水题,用结构体a了,用map居然wa了

Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6527    Accepted Submission(s): 2057


 

Problem Description

There is an analog clock with two hands: an hour hand and a minute hand. The two hands form an angle. The angle is measured as the smallest angle between the two hands. The angle between the two hands has a measure that is greater than or equal to 0 and less than or equal to 180 degrees.

Given a sequence of five distinct times written in the format hh : mm , where hh are two digits representing full hours (00 <= hh <= 23) and mm are two digits representing minutes (00 <= mm <= 59) , you are to write a program that finds the median, that is, the third element of the sorted sequence of times in a nondecreasing order of their associated angles. Ties are broken in such a way that an earlier time precedes a later time.

For example, suppose you are given a sequence (06:05, 07:10, 03:00, 21:00, 12:55) of times. Because the sorted sequence is (12:55, 03:00, 21:00, 06:05, 07:10), you are to report 21:00.

 

 

Input

The input consists of T test cases. The number of test cases (T) is given on the first line of the input file. Each test case is given on a single line, which contains a sequence of five distinct times, where times are given in the format hh : mm and are separated by a single space.

 

 

Output

Print exactly one line for each test case. The line is to contain the median in the format hh : mm of the times given. The following shows sample input and output for three test cases.

 

 

Sample Input

 

3 00:00 01:00 02:00 03:00 04:00 06:05 07:10 03:00 21:00 12:55 11:05 12:05 13:05 14:05 15:05

 

 

Sample Output

 

02:00 21:00 14:05

 

 

Source

Asia 2003(Seoul)

 

#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
struct k
{
    string k1;
    double k2;
}s[5];
double cmp(k x,k y)
{
    if(x.k2==y.k2)
    return x.k1<y.k1;
    else
    return x.k2<y.k2;
}
double angle(int h,int m)
{
    double a=0;
    int i,j;
    a=fabs(h*30.0+m*0.5-m*6.0);
    if(a>360)
    a-=360.0;
    if(a>180)
    a=360.0-a;
    //cout<<h<<"  "<<m<<"  "<<a<<endl;
    return a;
}
int main()
{
    //freopen("1.txt","r",stdin);
    int i,j,n,e,h,m;
    double an=0;
    map<string,double> w;
    vector<double> q;
    string a;
    cin>>n;
    while(n--)
    {
        e=5;
        while(e--)
        {
            cin>>a;
            h=(a[0]-'0')*10+a[1]-'0';
            m=(a[3]-'0')*10+a[4]-'0';
            s[5-e-1].k1=a;
            s[5-e-1].k2=angle(h,m);
        }
        sort(s,s+5,cmp);
        cout<<s[2].k1<<endl;
    }
    return 0;
}

 

 

我正在编辑c++代码,请帮我检查并改正错误点。我的原始代码如下: #include<bits/stdc++.h> using namespace std; #define ll long long const int N=1e5+5; int n,m; struct Node{ int x,y,z; }a[2*N]; bool cmp1(Node x,Node y){ if(x.x!=y.x){ return x.x<y.x; } if(x.z!=y.z){ return x.z>y.z; } if(x.y!=y.y){ return x.y<y.y; } return 1; } bool cmp2(Node x,Node y){ if(x.x!=y.x){ return x.x>y.x; } if(x.z!=y.z){ return x.z>y.z; } if(x.y!=y.y){ return x.y<y.y; } return 1; } ll ans[N]; map<int,int>to; class xdtr{ public: struct Node{ int l,r; ll mi; Node *cl,*cr; int mid(){ return (l+r)/2; } }; inline Node* add(int l,int r){ return new Node{l,r,(int)1e18,nullptr,nullptr}; } Node *head; inline xdtr(int br=1e6){ head=add(0,br); } inline Node* zl(Node *x){ if(x->cl==nullptr){ x->cl=add(x->l,x->mid()); } return x->cl; } inline Node* zr(Node *x){ if(x->cr==nullptr){ x->cr=add(x->mid()+1,x->r); } return x->cr; } inline void push_up(Node *x){ x->mi=1e18; if(x->cl!=nullptr){ x->mi=min(x->mi,x->cl->mi); } if(x->cr!=nullptr){ x->mi=min(x->mi,x->cr->mi); } } int l,r,a; ll query(Node *x){ if(x==nullptr){ return 1e18; } if((l<=x->l)&&(x->r<=r)){ return x->mi; } ll ans=1e18; if(l<=x->mid()){ ans=min(ans,query(x->cl)); } if(x->mid()<r){ ans=min(ans,query(x->cr)); } return ans; } void update(Node *x){ if((x->l)==(x->r)){ x->mi=min(x->mi,(ll)a); return; } if(r<=x->mid()){ update(zl(x)); }else{ update(zr(x)); } push_up(x); } inline ll query(int wl,int wr){ l=to[wl]; r=to[wr]; return query(head); } inline void update(int wr,ll wa){ r=to[wr]; a=wa; update(head); } }w1,w2,w3,w4; map<int,int>mp; int main(){ cin>>n>>m; for(int i=1;i<=n;++i){ cin>>a[i].x>>a[i].y>>a[i].z; mp[a[i].x]=0; mp[a[i].y]=0; } for(int i=1;i<=m;++i){ cin>>a[n+i].x>>a[n+i].y; mp[a[n+i].x]=0; mp[a[n+i].y]=0; a[n+i].z=-i; ans[i]=abs(a[n+i].x-a[n+i].y); } mp[0]=0; mp[1e6]=0; int h=0; for(auto it=mp.begin();it!=mp.end();++it){ to[it->first]=++h; } sort(a+1,a+1+n+m,cmp1); for(int i=1;i<=n+m;++i){ if(a[i].z<0){ ans[-a[i].z]=min(ans[-a[i].z],w2.query(0,a[i].y)+a[i].x+a[i].y); ans[-a[i].z]=min(ans[-a[i].z],w3.query(a[i].y,1e6)+a[i].x-a[i].y); }else{ w2.update(a[i].y,-a[i].x-a[i].y+a[i].z); w3.update(a[i].y,-a[i].x+a[i].y+a[i].z); } } sort(a+1,a+1+n+m,cmp2); for(int i=1;i<=n+m;++i){ if(a[i].z<0){ ans[-a[i].z]=min(ans[-a[i].z],w1.query(0,a[i].y)-a[i].x+a[i].y); ans[-a[i].z]=min(ans[-a[i].z],w4.query(a[i].y,1e6)-a[i].x-a[i].y); }else{ w1.update(a[i].y,+a[i].x-a[i].y+a[i].z); w4.update(a[i].y,+a[i].x+a[i].y+a[i].z); } } for(int i=1;i<=m;++i){ cout<<ans[i]<<endl; } return 0; } # P4088 [USACO18FEB] Slingshot P ## 目描述 Farmer John 最不喜欢的农活之一就是到处搬运牛粪。为了简化这一过程,他想出了一个有趣的主意:与其用拖拉机后面的拖车搬运牛粪,为什么不通过一个巨大的牛粪弹弓将其射到空中呢?(确实,可能会出什么问呢……) Farmer John 的农场建在一条笔直的长路上,因此农场上的任何位置都可以简单地用其在这条路上的位置来描述(实际上就是数轴上的一个点)。FJ 建造了 $N$ 个弹弓($1 \leq N \leq 10^5$),其中第 $i$ 个弹弓由三个整数 $x_i$、$y_i$ 和 $t_i$ 描述,表示这个弹弓可以将牛粪从位置 $x_i$ 射到位置 $y_i$,仅需 $t_i$ 个单位时间。 FJ 有 $M$ 堆牛粪需要搬运($1 \leq M \leq 10^5$)。第 $j$ 堆牛粪需要从位置 $a_j$ 搬运到位置 $b_j$。用拖拉机搬运牛粪,每移动距离 $d$ 需要 $d$ 个单位时间。FJ 希望通过允许每堆牛粪最多使用一次弹弓来减少搬运时间。FJ 在没有牛粪的情况下移动拖拉机的时间不计入搬运时间。 对于每堆牛粪,请帮助 FJ 确定在最多使用一次弹弓的情况下,搬运所需的最少时间。 ## 输入格式 输入的第一行包含 $N$ 和 $M$。接下来的 $N$ 行每行描述一个弹弓,包含三个整数 $x_i$、$y_i$ 和 $t_i$($0 \leq x_i, y_i, t_i \leq 10^9$)。最后的 $M$ 行描述需要搬运的牛粪堆,每行包含两个整数 $a_j$ 和 $b_j$。 ## 输出格式 输出 $M$ 行,每行对应一堆牛粪,表示搬运所需的最少时间。 ## 输入输出样例 #1 ### 输入 #1 ``` 2 3 0 10 1 13 8 2 1 12 5 2 20 7 ``` ### 输出 #1 ``` 4 3 10 ``` ## 说明/提示 在这里,第一堆牛粪需要从位置 $1$ 搬运到位置 $12$。如果不使用弹弓,这将花费 $11$ 个单位时间。然而,使用第一个弹弓,花费 $1$ 个单位时间将牛粪移动到位置 $0$(弹弓的起点),$1$ 个单位时间将牛粪射到位置 $10$(弹弓的终点),然后花费 $2$ 个单位时间将牛粪移动到位置 $12$。第二堆牛粪最好不使用弹弓搬运,而第三堆牛粪应使用第二个弹弓搬运。 目来源:Brian Dean
最新发布
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值