题意:告诉你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;
}

  

代码如下:

最新文章

  1. 初探Socket
  2. AngularJs:Service、Factory、Provider依赖注入使用与区别
  3. springmvc 表单提交
  4. json日期转换
  5. MySQL5.6下使用xtrabackup部分备份恢复到MySQL5.7
  6. eclipse中项目右上方有一个s,eclipse中项目左下方友谊个红色的叉,eclipse中项目左下方友谊个红色的感叹号
  7. 关于IT概念的一些思考
  8. [LeetCode] Combinations (bfs bad、dfs 递归 accept)
  9. java+mysql中文乱码问题
  10. GotoTest
  11. C++ concepts: Compare
  12. DataTable源码分析(二)
  13. TCP三次握手四次挥手过程及各过程中客户端和服务器端的状态。
  14. 7系列高速收发器总结 GTP IP核使用篇
  15. FreeRTOS数据结构(一)--链表和链表项
  16. python设计模式第二十三天【状态模式】
  17. nmap学习之相关参数列表
  18. smtp常见问题
  19. create-react-app脚手架的安装和目录结构介绍
  20. 版本号比较函数-js

热门文章

  1. Java_10 继承
  2. Android的事件分发机制
  3. Head First Servlets &amp; JSP 学习笔记 第三章 —— MVC迷你教程
  4. 操作符offset
  5. echarts柱状图图例不显示的问题
  6. python bisect 排序模块 二分查找与 bisect 模块
  7. C++树的插入和遍历(关于指针的指针,指针的引用的思考)
  8. andorid 菜单 进度条
  9. poj 1321 (简单DFS) 棋盘问题
  10. tmux 快捷操作