跳过正文
  1. Posts/

codeforces 31 C. Schedule

·2 分钟

http://codeforces.com/problemset/problem/31/C 题意:给出n个借用教室的时间安排,可能会有冲突。要求恰好去掉一个时间安排使得剩下的时间安排不冲突。问多多少种方案。 思路:首先一个直觉是。。除非初始就没有任何冲突。。不然这个答案不会很大。。

如果没有任何冲突,那么答案为n,直接输出一遍就好。

以l为第一关键字,r为第二关键字升序sort下。

如果有一个冲突,那么要看是否有包含关系,如果有,需要去掉大的这个,方案数为1.如果只是相交,那么可以去掉任意一个。方案数为2.

如果有两个冲突,我要看这两个冲突涉及到几个时间安排,如果涉及到4个或者时间安排,那么不可能全部解决,die掉。

如果这两个冲突涉及到三个时间安排,也就是说中间的和两段的相交,那么可以取消中间的这个时间安排来解决冲突。方案数为1.

需要注意的是输出的时候要按照原来的顺序。。所以存的时候记得存一下id.因为排序以后会打乱原有。输出之前还要sort下。 忘了这个。。WA#22/。因为按照id未必是从小到大输出的。

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2015年12月29日 星期二 21时37分11秒
  4File Name :code/cf/problem/31C.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 lson l,m,rt<<1
 20#define rson m+1,r,rt<<1|1
 21#define ms(a,x) memset(a,x,sizeof(a))
 22typedef long long LL;
 23#define pi pair < int ,int >
 24#define MP make_pair
 25
 26using namespace std;
 27const double eps = 1E-8;
 28const int dx4[4]={1,0,0,-1};
 29const int dy4[4]={0,-1,1,0};
 30const int inf = 0x3f3f3f3f;
 31const int N=5E3+7;
 32int n ;
 33int ans[N];
 34
 35struct node
 36{
 37    int fst,sec;
 38    int id;
 39
 40    bool operator <(node b)const
 41    {
 42	if (fst<b.fst) return true;
 43	if (fst==b.fst&&sec<b.sec) return true;
 44	return false;
 45    }
 46}a[N];
 47int main()
 48{
 49	#ifndef  ONLINE_JUDGE
 50	freopen("code/in.txt","r",stdin);
 51  #endif
 52	cin>>n;
 53	for ( int i = 1 ; i <= n ; i++) cin>>a[i].fst>>a[i].sec,a[i].id = i ;
 54
 55	sort(a+1,a+n+1);
 56
 57//	for ( int i = 1 ; i <= n ; i++) cout<<a[i].fst<<endl;
 58	a[n+1].fst = inf;
 59	int num = 0 ;
 60	bool ill=false,die=false;
 61	for ( int i = 1 ; i <= n ; i++)
 62	{
 63	    int j = i+1;
 64	    int cnt =  0;
 65	    while (a[j].fst<a[i].sec&&j<=n)
 66	    {
 67	//	cout<<"i:"<<i<<" j:"<<j<<endl;
 68		if (ill)
 69		{
 70		    die = true;
 71		    break;
 72		}
 73		j++;
 74		cnt++;
 75	    }
 76	    if (die) break;
 77
 78	    if (cnt==0) continue;
 79	    ill = true;
 80	    j--;
 81
 82	    if (cnt>=2)
 83	    {
 84		num++;
 85		ans[num] = a[i].id;
 86	    }
 87	    else
 88	    {
 89		if (a[j+1].fst<a[j].sec&&j+1<=n)
 90		{
 91		    num++;
 92		    ans[num] =  a[j].id;
 93		    i++;
 94		}
 95		else
 96		{
 97		    num++;
 98		    ans[num] =  a[i].id;
 99		    num++;
100		    ans[num] =  a[j].id;
101		}
102	    }
103	}
104	if (die)
105	{
106	  //  cout<<"wwwww"<<endl;
107	    puts("0");
108	    return 0;
109	}
110	if (!ill)
111	{
112	    cout<<n<<endl;
113	    for ( int i = 1 ; i <= n-1 ; i++) printf("%d ",i);
114	    printf("%d\n",n);
115	}
116	else
117	{
118	    cout<<num<<endl;
119	    sort(ans+1,ans+num+1);  //id的顺序未必是升序。所以需要再次sort下。
120	    for (  int i =1 ; i <= num-1  ; i++) printf("%d ",ans[i]);
121	    printf("%d\n",ans[num]);
122	}
123
124  #ifndef ONLINE_JUDGE
125  fclose(stdin);
126  #endif
127    return 0;
128}

相关文章

codeforces 1 B. Spreadsheets

·2 分钟
http://codeforces.com/problemset/problem/1/B 题意:给出了两种表格的表示方法。要求互相转化。 思路:直接模拟即可。注意和一般的进制转化不同的是,26进制对应的是1到26而不是0到25,所以要记得处理下借位。

codeforces 158 B. Taxi

·1 分钟
http://codeforces.com/problemset/problem/158/B 题意:n组人,每组有si个(1<=si<=4),每辆车能装4个人。问最少需要多少辆车装下所有人并且保证同一组的人在一辆车里。 思路:统计人数分别为1,2,3,4的人数。对于4的直接加到答案。贪心的思路是:优先用人数少的去填人数多的。

codeforces # 317 div 2 B. Order Book(模拟)

·3 分钟
B. Order Book time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In this task you need to process a set of stock exchange orders and use them to create order book.

bc #52 div 2 A ||hdoj5417 Victor and Machine (模拟)

·1 分钟
傻逼模拟题 我做了半小时…. sssssad 1/************************************************************************* 2 > File Name: code/bc/#52/1001.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年08月22日 星期六 18时51分44秒 6 ************************************************************************/ 7#include<iostream> 8#include<iomanip> 9#include<cstdio> 10#include<algorithm> 11#include<cmath> 12#include<cstring> 13#include<string> 14#include<map> 15#include<set> 16#include<queue> 17#include<vector> 18#include<stack> 19#include<cctype> 20#define y1 hust111qqz 21#define yn hez111qqz 22#define j1 cute111qqz 23#define ms(a,x) memset(a,x,sizeof(a)) 24#define lr dying111qqz 25using namespace std; 26#define For(i, n) for (int i=0;i<int(n);++i) 27typedef long long LL; 28typedef double DB; 29const int inf = 0x3f3f3f3f; 30const int N=1E6+7; 31int main() 32{ 33 #ifndef ONLINE_JUDGE 34 freopen("in.txt","r",stdin); 35 #endif 36 int x,y,w,n; 37 while (scanf("%d%d%d%d",&x,&y,&w,&n)!=EOF){ 38 int num = 1; 39 int cnt; 40 int q; 41 bool on = true; 42 bool flag = false; 43 int t = 0; 44 while (t<N&&!flag){ 45 if (num==n) { 46 cout<<t<<endl; 47 flag = true; 48 break; 49 } 50 cnt = t+x; 51 q = 0; 52 while (t<cnt){ 53 q++; 54 t++; 55 if (q%w==0){ 56// cout<<"aaat:"<<t<<endl; 57 num++; 58 } 59 if (num == n){ 60 cout<<t<<endl; 61 flag = true; 62 break; 63 } 64 } 65 on = false; 66 t = t + y; 67 on = true; 68 num++; 69 if (num==n){ 70 cout<<t<<endl; 71 flag = true; 72 } 73 } 74 } 75 #ifndef ONLINE_JUDGE 76 fclose(stdin); 77 #endif 78 return 0; 79}