Illegal or Not?
来源:互联网 发布:快手特效视频软件 编辑:程序博客网 时间:2024/06/06 14:17
The Schengen Agreement was signed by a number of countries to uniform many visa-related questions and to allow tourists from outside of the Schengen area to enter and freely travel within Schengen member states using only one visa. A multiple-entry visa owner can perform many travels to any Schengen member state using a single visa, but migration laws limit the number of days he is allowed to stay there. Forany consecutive 180 days a visa owner is only allowed to be inside the Schengen area for no more than90 days in total.
A tourist has got his 5-year Schengen multiple-entry visa on October 18th 2010, therefore he could travel to and from the Schengen area at any of5·365 + 1 (2012 was a leap year) = 1826 days.
Yesterday (October 17th, 2015) was the last day his visa was valid, and the tourist wants to know whether he has broken the migration laws and may face problems with obtaining a new Schengen visa. You are given the information about all trips to the Schengen member states he did using this visa and are to verify the rule about consecutive days for multiple-entry visa holders. According to the Schengen visa rules the day of arrival and the day of departure are considered to be days spent inside the Schengen area.
The first line of the input contains only number of trips n (1 ≤ n ≤ 1826).
The i-th of the following n lines describes the i-th trip with two integersai anddi — the day of arrival to Schengen area and the day of departure respectively (1 ≤ ai ≤ di ≤ 1826). Days are numbered starting from the day the visa was issued.
It is guaranteed that these trips do not overlap, that is, each of 1826 days is a part of no more than one trip. Trips are given in arbitrary order.
Output "Yes" (without quotes) if the tourist has followed the rules and may not worry about a new visa. Print "No" (without quotes) if he needs to start to look for an explanation to give to migration officer.
12 91
Yes
11 91
No
23 91180 200
No
2181 2701 90
Yes
In the second sample the tourist was in Schengen area for 91 days in the 180-day window which starts on day 1.
In the third sample the tourist was in Schengen area for 91 days in the 180-day window which started on day 2 (89 days from day 3 to day 91 and 2 days from day 180 to day 181).
题意就是说这个人从1到1826天内可以进入这个国家,但是在连续的180天内,不能待超过90天,给出,他来的时间和离开的时间,看是否符合条件
思路:开一个数组s[]如果第i天在这个国家是s[i]标记为1否则记为0,然后就跑连续的180天看是s[i]到s[i+180]的和是否大于90就行了;
可以先将最开始180天的和跑出来,剩下的每次减去第一天的然后加上第181天的在o(n)的时间内就能全部跑完。
#include <iostream>#include <cstdio>#include <cmath>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <vector>#include <stack>#include <map>#define inf 0x3f3f3f3fusing namespace std;int s[2000];int main(){ios::sync_with_stdio(false);int n, l, r, i, j, sum, flag;while(cin>>n){memset(s,0,sizeof(s));sum = 0;while(n--){cin>>l>>r;for(i = l;i <= r;i++)s[i] = 1;}for(i = 1;i <= 180;i++){sum += s[i];}flag = 1;if(sum > 90){flag = 0;}if(flag){for(i = 1,j = 181;j <= 1826;i++,j++){sum = sum - s[i] + s[j];if(sum > 90){flag = 0;break;}}}if(flag)cout<<"Yes"<<endl;elsecout<<"No"<<endl;} return 0;}
- Illegal or Not?
- telnet报错:Name or service not known: Illegal seek
- c/c++ error C2614: illegal member initialization: is not a base or member
- 2015-2016 ACM-ICPC, NEERC, Moscow Subregional Contest I题:Illegal or Not? [暴力题]
- HDU 3342 legal or illegal
- ORA-01506: missing or illegal database name
- ORA-01506: missing or illegal database name
- Illegal key size or default parameters
- ORA-01506: missing or illegal database name
- ORA-01506: missing or illegal database name
- java的安全异常Illegal key size or default parameters
- 证书问题Illegal key size or default parameters
- java.security.InvalidKeyException: Illegal key size or default parameters
- java.security.InvalidKeyException: Illegal key size or default parameters
- java.security.InvalidKeyException: Illegal key size or default parameters
- Illegal offset type in isset or empty in in project
- Java Security: Illegal key size or default parameters
- 异常:java.security.InvalidKeyException: Illegal key size or default parameters
- 能量球效果(贝塞尔曲线)
- 漫谈
- 阿里巴巴代码规约插件使用
- navicat for Mac的备份【windows和Mac】
- 【坐在马桶上看算法】算法2:邻居好说话:冒泡排序
- Illegal or Not?
- JAVA 网络编程简单示例
- android-自定义相机遇小米3生成图片花屏
- linux 并发服务器 demo
- 关于javax.mail.NoSuchProviderException:Invalid protocal:null的坑
- Error:Execution failed for task ':app:mergeDebugResources'. > Error: java.util.concurrent.ExecutionE
- 认识分支结构if
- 匿名内部类----应用
- pygame安装说明