题目链接:https://cn.vjudge.net/contest/283924#problem/B

题目大意:给你n个人的信息,让你找出一个时间,要求让你选择一天,使得这一天的前一个生日距离它最远,如果有多个一样的,有点选择10月27之后的。

AC代码:

 #include<iostream>
#include<stack>
#include<cstring>
#include<iomanip>
#include<stdio.h>
#include<algorithm>
#include<cmath>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
# define lson l,m,rt<<
# define rson m+,r,rt<<|
const int maxn = 2e5+;
struct node
{
int m;
int d;
int day;
bool friend operator < (node t1,node t2)
{
return t1.day<t2.day;
}
} q[maxn];
char u;
char str[maxn];
int sto[maxn];
int a[maxn];
int f[]= {,,,,,,,,,,,};
int cal(int t1,int t2)
{
int ans=;
for(int i=; i<t1-; i++)
{
ans+=f[i];
}
ans+=t2;
return ans;
}
int main()
{
// freopen("data1.in","r",stdin);
int n,m,d;
scanf("%d",&n);
if(n==)
{
cin>>str;
cin>>q[].m>>u>>q[].d;
int i,tot=cal(q[].m,q[].d)-;
for( i=; i<; i++)
{
if(tot-f[i]>=)
tot-=f[i];
else
break;
}
if(tot==)
{
i--;
if(i==-)
i=;
tot=f[i];
}
printf("%02d-%02d\n",i+,tot);
return ;
}
for(int i=; i<=n; i++)
{
cin>>str;
cin>>q[i].m>>u>>q[i].d;
q[i].day=cal(q[i].m,q[i].d);
}
sort(q+,q+n+);
sto[]=-q[n].day+q[].day;
for(int i=; i<=n; i++)
{
sto[i]=q[i].day-q[i-].day;
}
int maxx=;
for(int i=; i<=n; i++)
{
maxx=max(maxx,sto[i]);
}
int num=,id;
for(int i=; i<=n; i++)
{
if(maxx==sto[i])
{
a[++num]=i;
}
}
// cout<<num<<endl;
if(num==)
{
int i,tot=sto[a[]]+q[a[]-].day-;
if(a[]==)tot=q[].day-;
tot=(tot+)%;
for(i=; i<; i++)
{
if(tot-f[i]>=)
tot-=f[i];
else
break;
}
if(tot==)
{
i--;
if(i==-)
i=;
tot=f[i];
}
printf("%02d-%02d\n",i+,tot);
}
else
{
int flag=;
int minn1=inf;
int minn2=inf;
int pos;
for(int i=; i<=num; i++)
{
int tmp=sto[a[i]]+q[a[i]-].day-;
if(tmp>)
tmp-=;
if(tmp>cal(,))
{
if(tmp-cal(,)<minn1)
{
minn1=tmp-cal(,);
flag=i;
}
}
else
{
if((tmp-cal(,))<minn2)
{
minn2=tmp-cal(,);
pos=i;
}
}
}
// cout<<minn1<<endl;
int i,tot;
if(minn1!=inf)
{
i,tot=sto[a[flag]]+q[a[flag]-].day-;
tot=(tot+)%;
for( i=; i<; i++)
{
if(tot-f[i]>=)
tot-=f[i];
else
break;
}
}
else
{
tot=q[pos].day-;
tot=(tot+)%;
for( i=; i<; i++)
{
if(tot-f[i]>=)
tot-=f[i];
else
break;
}
}
if(tot==)
{
i--;
if(i==-)
i=;
tot=f[i];
}
printf("%02d-%02d\n",i+,tot);
}
return ;
}

B - Birthday Boy Gym - 102007B的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. 认真学习Linux系统让你真的有收获

    学习,最重要的是有一个认真的态度,熟话说,读书可以改变命运,以前觉得并不一定是这样,其实经历的多了才知道,事实确实如此.试想一个不会写字看书的人,他的生活该有多么无聊.读书容易,但读好书并不总是件容易 ...

  2. BZOJ1563 NOI2009诗人小G(动态规划+决策单调性)

    设f[i]为前i行的最小不协调度,转移枚举这一行从哪开始,显然有f[i]=min{f[j]+abs(s[i]-s[j]+i-j-1-m)p}.大胆猜想有决策单调性就好了.证明看起来很麻烦,从略.注意需 ...

  3. jQuery文档处理总结

    <!DOCTYPE html> <html lang="cn"> <head> <meta charset="UTF-8&quo ...

  4. hdu 6319 Problem A. Ascending Rating (2018 Multi-University Training Contest 3 A)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=6319 思路: 单调队列倒着维护,队列里面剩下的值的数量就是这一段区间的count值,如样例第一个区间:3 ...

  5. startSSL 申请免费的SSL证书

    打开网址https://www.startssl.com/?app=12,选择Sign-up注册. 输入个人注册信息 需注意以下几点:(1)地址必须详细,否则你会收到这样的邮件: Please pro ...

  6. BZOJ5312 冒险(势能线段树)

    BZOJ题目传送门 表示蒟蒻并不能一眼看出来这是个势能线段树. 不过仔细想想也并非难以理解,感性理解一下,在一个区间里又与又或,那么本来不相同的位也会渐渐相同,线段树每个叶子节点最多修改\(\log ...

  7. JOISC 2017 自然公园

    吐槽 YMD的课件是真的毒,YYB的也很毒. 题目链接 LOJ sol 我是一个一个Subtask做的... Subtask 1 \(O(n^2)\)枚举每两个点有没有边即可. Subtask 2 链 ...

  8. UOJ #164. 【清华集训2015】V | 线段树

    题目链接 UOJ #164 题解 首先,这道题有三种询问:区间加.区间减(减完对\(0\)取\(\max\)).区间修改. 可以用一种标记来表示--标记\((a, b)\)表示把原来的值加上\(a\) ...

  9. poj1038 Bugs Integrated,Inc. (状压dp)

    题意:N*M的矩阵,矩阵中有一些坏格子,要在好格子里铺2*3或3*2的地砖,问最多能铺多少个. 我的方法好像和网上流传的方法不太一样...不管了.... 由数据范围很容易想到状压dp 我们设某个状态的 ...

  10. A1073. Scientific Notation

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...