跳过正文
  1. Posts/

codeforces #336 div 2 A. Saitama Destroys Hotel

·1 分钟

http://codeforces.com/contest/608/problem/A 题意:一个电梯,从s到0层,单项,给出n个人,每个人在某时间出现在某层,问要花多长时间把所有人运到0。初始电梯在s,每下一层话费时间1,上来人不花时间。 思路:由于电梯只能是单项,那么到达某一层的时候,一定要等到把这层中最晚来的那个接走。所以排序的时候按照楼层高到低为第一关键字,等待时间长到短为第二关键字。对于同一楼层出现的,只考虑第一个即可,也就是最后出现的。需要注意的是最后接完最后一个人以后把电梯运行道0层。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2015年12月24日 星期四 00时32分24秒
 4File Name :code/cf/#336/A.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=105;
34int n;
35int s;
36struct node
37{
38    int f,t;
39
40    bool operator <(node b)const
41    {
42	if (f>b.f) return true;
43	if (f==b.f&&t>b.t) return true;
44	return false;
45    }
46}q[N];
47int main()
48{
49	#ifndef  ONLINE_JUDGE
50	freopen("code/in.txt","r",stdin);
51  #endif
52	cin>>n>>s;
53	for ( int i =  1 ; i<= n ;i++) cin>>q[i].f>>q[i].t;
54
55	sort(q+1,q+n+1);
56	int cur = s;
57	int t = 0 ;
58	q[0].f = -1;
59//	for ( int i = 1 ; i <= n ; i++) cout<<q[i].f<<" "<<q[i].t<<endl;
60	for ( int i = 1 ; i <= n ; i++)
61	{
62	    if (q[i].f==q[i-1].f) continue;
63	    t+=cur-q[i].f;
64	   // cout<<"t:"<<t<<" ";
65	    cur = q[i].f;
66	    if (t<q[i].t)
67	    {
68		t = q[i].t;
69	    }
70	  //  cout<<"t2:"<<t<<endl;
71	}
72	t+=q[n].f;
73	cout<<t<<endl;
74
75  #ifndef ONLINE_JUDGE
76  fclose(stdin);
77  #endif
78    return 0;
79}

相关文章

codeforces 466 C. Number of Ways

·2 分钟
http://codeforces.com/problemset/problem/466/C 题意:给定一个序列。要将序列分成三个非零的连续部分,使得三部分的和相等。问有多少中分法。 思路:首先可以知道,如果是序列的和不为3的倍数,那么一定无解,输出0.设序列的和为sum,那么每一部分的和就应该为sum/3。我们可以预处理出从1开始的和为sum/3的点(我开了数组表示前缀和。。想了下其实不用。。我只需要点的信息。。所以用一个变量表示即可),将点的下标存在p[i]里。对于每一个p[i],我想要知道比p[i]大且补与p[i]相邻的点中,有多少个j,使得从j到n的和为sum/3。因为如果有两部分的和都为sum/3,那么剩下的那部分也一定为sum/3.然后要知道有多少个满足题意的j,我们可以从后往前扫一遍,标记从n开始往前扫,和为sum/3的点,可以用一个0,1数组表示。如果和为sum/3,那么标记为1,否则为0.然后再用一个类似前缀和的思路。再开一个数组c记录从j到n有的和为多少,也就是从j到n有多少个点满足该点到n的和为sum/3.

codeforces 522 A. Vanya and Table

http://codeforces.com/problemset/problem/552/A 题意:一个100*100的网格。然后给n个矩形。每个格子中填上包含这个格子的矩形的个数。最后问所有格子的和。 思路:树状数组搞得…然而..直接求所有矩形面积的和就可以啊喂。。o(n)。。。111qqz你个炒鸡大菜鸡。

codeforces 505 B. Mr. Kitayuta's Colorful Graph

·1 分钟
http://codeforces.com/contest/505/problem/B 题意;给一个图,边有颜色。给q个查询,每个查询一对点x,y。问只经过某种颜色的边使得x能到y颜色数目。 思路:存颜色的时候卡了下。。本来打算开一个二维的set用来存颜色。。。没想明白。。后来发现。。还是用vecotr就好啊。。。多开一维度vector。。或者。。vector 用 pair 都是可以的。。。因为颜色数不多。。可以暴力枚举每种颜色做一遍dfs 看只走有这条颜色的边x能否到y。。