题意:告诉你n 个科目的考试日期,在考试当天不能复习,每一个科目的最早复习时间不能早于考试时间的t天,每一天你可以复习完一科,也只能复习一科,求最晚的复习时间!。

析:由于题目给定的时间都在1900 ~ 2100 之间,所以先预处理时间,然后把每个科目按照考试时间最晚的优先策略进行排序,从后向前扫,看看能不能在规定时间内完成复习,然后维护一个优先队列,这个优先策略是开始时间减去 t 最大的优先,因为我们是从后向前找,肯定是越大越应该完成,要不然就完不成了,如果中间有完成不成的,就是不可能,否则就可以完成。由于代码写的不好,跑的很慢,效率比较低。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define be begin()
#define ed end()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,n,x) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.in", "r", stdin)
#define freopenw freopen("out.out", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 5e4 + 10;
const int maxm = 700 + 10;
const LL mod = 1000000007;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
}
inline int readInt(){ int x; scanf("%d", &x); return x; } struct Node{
int t, tim;
bool operator < (const Node &p) const{
return tim > p.tim || tim == p.tim && t < p.t;
}
};
Node a[maxn];
char s[20];
int date; bool is_leap_year(int n){
if(n % 400 == 0) return true;
if(n % 100 == 0) return false;
if(n % 4 == 0) return true;
return false;
} int cal(int y, int m, int d){
int ans = date;
for(int i = 1900; i < y; ++i) ans += is_leap_year(i) ? 366 : 365;
for(int i = 1; i < m; ++i) ans += is_leap_year(y) ? monn[i] : mon[i];
ans += d;
return ans;
} struct Sub{
int t, tim;
bool operator < (const Sub &p) const{
return tim - t < p.tim - p.t;
}
}; void print(int n){
int y, m;
for(int i = 0; ; ++i){
int t = is_leap_year(i) ? 366 : 365;
if(n > t) n -= t;
else{ y = i; break; }
}
for(int i = 1; ; ++i){
int t = is_leap_year(y) ? monn[i] : mon[i];
if(n > t) n -= t;
else{ m = i; break; }
}
printf("%02d.%02d.%04d\n", n, m, y);
} int main(){
date = 0;
for(int i = 0; i < 1900; ++i) date += is_leap_year(i) ? 366 : 365;
while(scanf("%d", &n) == 1){
for(int i = 0; i < n; ++i){
scanf("%s", s);
int y, m, d;scanf("%d.%d.%d", &d, &m, &y);
scanf("%d", &a[i].t);
a[i].tim = cal(y, m, d);
}
sort(a, a + n);
priority_queue<Sub> pq;
pq.push((Sub){a[0].t, a[0].tim});
bool ok = true;
int t = a[0].tim - 1;
for(int i = 1; i < n && ok; ++i){
int det = a[i-1].tim - a[i].tim - 1;
while(det-- > 0){
if(pq.empty()) break;
Sub x = pq.top(); pq.pop();
if(x.tim - x.t > t){
ok = false; break;
}
else --t;
}
pq.push((Sub){a[i].t, a[i].tim});
t = a[i].tim - 1;
}
while(!pq.empty()){
Sub x = pq.top(); pq.pop();
if(x.tim - x.t > t){
ok = false; break;
}
else --t;
} if(!ok) puts("Impossible");
else print(t + 1);
}
return 0;
}

  

代码如下:

POJ 3110 Jenny's First Exam (贪心)的更多相关文章

  1. [POJ 2586] Y2K Accounting Bug (贪心)

    题目链接:http://poj.org/problem?id=2586 题目大意:(真难读懂啊)给你两个数,s,d,意思是MS公司每个月可能赚钱,也可能赔钱,如果赚钱的话,就是赚s元,如果赔钱的话,就 ...

  2. poj 2010 Moo University - Financial Aid (贪心+线段树)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 骗一下访问量.... 题意大概是:从c个中选出n个 ...

  3. poj 1328 Radar Installation (简单的贪心)

    Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42925   Accepted: 94 ...

  4. POJ 2370 Democracy in danger(简单贪心)

    Democracy in danger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3388   Accepted: 25 ...

  5. 【POJ】1862:Stripies【贪心】【优先队列】

    Stripies Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20456   Accepted: 9098 Descrip ...

  6. POJ 2376 (区间问题,贪心)

    题目链接:http://poj.org/problem?id=2376 题目大意:选择一些区间使得能够覆盖1-T中的每一个点,并且区间数最少 题目分析:这道题目很明显可以用贪心法来解决.但题目没有看起 ...

  7. POJ 2586 Y2K Accounting Bug(贪心)

    题目连接:http://poj.org/problem?id=2586 题意:次(1-5.2-6.3-7.4-8.5-9.6-10.7-11.8-12),次统计的结果全部是亏空(盈利-亏空<0) ...

  8. poj 3069 Saruman's Army (贪心)

    简单贪心. 从左边开始,找 r 以内最大距离的点,再在该点的右侧找到该点能覆盖的点.如图. 自己的逻辑有些混乱,最后还是参考书上代码.(<挑战程序设计> P46) /*********** ...

  9. poj 2393 Yogurt factory(dp+贪心)

    奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S.求总体最低成本. 贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的.于是该周单位成本 ...

随机推荐

  1. ubuntu系列-很好用的截图工具shutter

    直接在ubuntu软件市场中搜索“shutter”下载即可

  2. bbs项目实现点赞和评论的功能

    一.点赞功能 思路是这样的: 1.对点赞和踩都设置一个相同的class,然后对这个class绑定点击事件 2.点击触发ajax请求,我们对赞的标签设置了一个class属性,对踩的标签没有设置这个cla ...

  3. 理解HTTP之keep-alive(转)

    理解HTTP之keep-alive 在前面一篇文章中讲了TCP的keepalive,这篇文章再讲讲HTTP层面keep-alive.两种keepalive在拼写上面就是不一样的,只是发音一样,于是乎大 ...

  4. 微信公众号开发(5)---使用开源组件开发公众号OAuth2.0网页授权授权登录

    搞清微信公众号授权登录的步骤步骤,我们的开发就完成了一大步 献上github 地址: https://github.com/Wechat-Group/weixin-java-tools/wiki/MP ...

  5. C++ 求最长递增子序列(动态规划)

    i 0 1 2 3 4 5 6 7 8 a[i] 1 4 7 2 5 8 3 6 9 lis[i] 1 2 3 2 3 4 3 4 5 时间复杂度为n^2的算法: //求最长递增子序列 //2019/ ...

  6. Spring配置文件XML详解

    1.bean的基本属性配置: <!-- id是bean的标识符,必须唯一,如果没有配置id,name默认为标识符 如果配置了id,有配置了name,那么name为别名 name可以设置多个别名, ...

  7. bootstrap日历控件

    bootstrap的日历控件: <link href="~/bootstrap/css/bootstrap.min.css" rel="stylesheet&quo ...

  8. 长时间没有操作putty就会断开连接是怎么回事?

    seconds between keepalives 设置为10就好了, 这个值有什么含义,服务器为了节省资源采取了一些措施,其中一条就是如果检测一个会话(session)几分钟或者几小时没有数据流入 ...

  9. 体验godaddy域名转入,添加A记录,及使用dnspod的NS

    有两个域名一直放在朋友那,这个朋友是个神人,经常换电话号码,联系非常不方便. 近日将域名转入到godaddy下面了,第一次做域名转移,很是好奇. 之前域名在21.cn注册的,朋友帮我申请域名转出后,2 ...

  10. 探索未知种族之osg类生物---呼吸分解之事件循环三

    那我们就开始处理这些事件中得到的所有的交互事件,首先我们要判断这些事件是否包含osg的退出事件,那什么情况下会触发这个退出事件呢?如果您运行过osg中example中的小例子的,聪明的你一定就会发现当 ...