B - Birthday Boy Gym - 102007B
题目链接: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的更多相关文章
- 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 ...
- ACM: Gym 101047K Training with Phuket's larvae - 思维题
Gym 101047K Training with Phuket's larvae Time Limit:2000MS Memory Limit:65536KB 64bit IO F ...
- ACM: Gym 101047E Escape from Ayutthaya - BFS
Gym 101047E Escape from Ayutthaya Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I6 ...
- ACM: Gym 101047B Renzo and the palindromic decoration - 手速题
Gym 101047B Renzo and the palindromic decoration Time Limit:2000MS Memory Limit:65536KB 64 ...
- Gym 101102J---Divisible Numbers(反推技巧题)
题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...
- Gym 100917J---Judgement(01背包+bitset)
题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...
- Gym 100917J---dir -C(RMQ--ST)
题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...
- Gym 101102D---Rectangles(单调栈)
题目链接 http://codeforces.com/gym/101102/problem/D problem description Given an R×C grid with each cel ...
- Gym 101102C---Bored Judge(区间最大值)
题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...
随机推荐
- instanceof判断的对象可以是接口
instanceof是Java的一个二元操作符(运算符) 用法 boolean result = object instanceof class instanceof通过返回一个布尔值来指出,这个对象 ...
- 自定义缓存设计(static缓存数据)
设计题 编程过程中,为了解决缓存数据共享的问题,常常会使用static关键字达到脱离具体实例化对象,在整个java进程生命周期内共享数据的目的.请编写一个类,类名为MapCache,拥有但不局限于以下 ...
- 【转】linux环境内存分配原理 malloc info
Linux的虚拟内存管理有几个关键概念: Linux 虚拟地址空间如何分布?malloc和free是如何分配和释放内存?如何查看堆内内存的碎片情况?既然堆内内存brk和sbrk不能直接释放,为什么不全 ...
- BZOJ 1124: [POI2008]枪战Maf(构造 + 贪心)
题意 有 \(n\) 个人,每个人手里有一把手枪.一开始所有人都选定一个人瞄准(有可能瞄准自己).然后他们按某个顺序开枪,且任意时刻只有一个人开枪. 因此,对于不同的开枪顺序,最后死的人也不同. 问最 ...
- 自学Aruba5.1.2-带宽限制
点击返回:自学Aruba之路 自学Aruba5.1.2-带宽限制 1 针对role --可以限制所有数据 注:带宽限制需要PEFNG许可证 单位可以是kbits或是mbits 可以是上传(up ...
- Java核心技术-并发
多任务(multitasking):在同一时刻运行多个程序的能力. 并发执行的进程数目并不是由CPU数目制约的.操作系统将CPU的时间片分配给每一个进程,给人并发处理的感觉. 多线程程序在较低的层次上 ...
- 【bzoj3064】 CPU监控
http://www.lydsy.com/JudgeOnline/problem.php?id=3064 (题目链接) 题意 给出一个长度为$n$的数列$A$,同时定义一个辅助数组$B$,$B$开始与 ...
- 树莓派上使用Slowloris进行DDoS攻击
安装Slowloris工具 git clone https://github.com/gkbrk/slowloris.git 使用Slowloris进行攻击 进入Slowloris文件夹.cd slo ...
- 【POJ1952】逢低吸纳 dp+计数
题目大意:给定一个有 N 个数的序列,求其最长下降子序列的长度,并求出有多少种不同的最长下降子序列.(子序列各项数值相同视为同一种) update at 2019.4.3 题解:求最长下降子序列本身并 ...
- 【POJ1015】Jury compromise 多个费用的背包
这是一道比较综合的动态规划问题. 首先,根据题目中的从N个人中选出M个人,并且要使得某个目标函数最优,可以想到是背包问题,且因为要取出M个人,人数也应该作为背包体积的一个维度. 其次,要求输出路径,因 ...