Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499
You have decided to watch the best moments of some movie. There are two buttons on your player:
- Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next minute of the movie.
- Skip exactly x minutes of the movie (x is some fixed positive integer). If the player is now at the t-th minute of the movie, then as a result of pressing this button, it proceeds to the minute (t + x).
Initially the movie is turned on in the player on the first minute, and you want to watch exactly n best moments of the movie, the i-th best moment starts at the li-th minute and ends at the ri-th minute (more formally, the i-th best moment consists of minutes: li, li + 1, ..., ri).
Determine, what is the minimum number of minutes of the movie you have to watch if you want to watch all the best moments?
题意:你正在观看电影,现在有两个按钮1和2,如果你在电影t分钟时选择按钮1,电影会进入到t+1分钟;如果你在t分钟选择按钮2,电影在跳到t+x分钟。现在给出了电影中n个你想要看的精彩连续片段,假如你此时在电影的开头(即第一分钟),求出你最少要观看电影多少分钟。
解法:题目中给出的n个片段[Li,Ri]都是按照时间顺序排好了的(Ri-1<Li),所以我们不需要排序,直接模拟这个过程即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=;
int main()
{
int n;
int l,L,R;
int x;
while (scanf("%d%d",&n,&x)!=EOF)
{
int total=;
l=;
for (int i= ;i<n ;i++)
{
scanf("%d%d",&L,&R);
while (l+x<=L) {l+=x;if (l+x>L) break; }
total += R-l+;
l=R+;
}
printf("%d\n",total);
}
return ;
}
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes.
You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning.
You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language.
You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
题意:给出n行单词表,每一行两个意思相同、拼写不同的单词,每个单词出现一次。接下来给出m个上述单词表出现过的单词,要求对m个单词中每个词输出单词表中对应的一行中的一个单词,输出要求:输出单词长度短的那一个;如果两个单词长度一样,则输出单词表中对应那一行的第一个单词。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=+;
char str[maxn][][];
int n,m;
char S[];
int main()
{
while (scanf("%d%d",&n,&m)!=EOF)
{
for (int i= ;i<m ;i++) scanf("%s%s",str[i][],str[i][]);
for (int i= ;i<n ;i++)
{
scanf("%s",S);
for (int j= ;j<m ;j++)
{
int len=strlen(str[j][]);
int len2=strlen(str[j][]);
if (strcmp(str[j][],S)== || strcmp(str[j][],S)==) {
if (len>len2)
{
if (i) printf(" ");
printf("%s",str[j][]);
break;
}
else
{
if (i) printf(" ");
printf("%s",str[j][]);
break;
}
}
}
}
printf("\n");
}
return ;
}
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and biare not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
题意:给出n条不重叠的直线,把平面划分了很多区域,给出了你家的位置和学校的位置(都保证在区域里,不会在交点和直线上),求出从家的位置到学校的最少步数(一步定义为从一个区域内部到和它有公共的长度不为0的边界的区域内部)。

说明:上图中A和B的距离就为2(因为A和B区域没有公共的不为0的边界,不能直接到达)。
解法:比赛最开始想到的就是求出每个区域,然后给每个区域编号,相邻区域连一条边,权值为1,不相邻的为无限大,然后Dijkstra算法或者Floyd算法搞。后来想想MD这么复杂。思考了一会,发现我们知道了A和B的位置,如果给出当前一条直线,这条直线让AB两点同侧的话,就对AB的最短路径没有影响,如果让AB异侧,就等同于在AB路径上加1即可,这样就简单多了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
#define exp 1e-10
#define PI 3.141592654
using namespace std;
typedef long long ll;
int main()
{
ll x1,y1,x2,y2;
int n;
ll a,b,c;
while (scanf("%I64d%I64d",&x1,&y1)!=EOF)
{
scanf("%I64d%I64d",&x2,&y2);
scanf("%d",&n);
ll ans=;
for (int i= ;i<n ;i++)
{
scanf("%I64d%I64d%I64d",&a,&b,&c);
ll num=a*x1+b*y1+c;
ll num2=a*x2+b*y2+c;
if ((num<&&num2>)||(num>&&num2<)) ans++;
}
printf("%I64d\n",ans);
}
return ;
}
后续:感谢提出宝贵的意见。。。
Codeforces Round #284 (Div. 2)的更多相关文章
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何
A. Crazy Town 题目连接: http://codeforces.com/contest/498/problem/A Description Crazy Town is a plane on ...
- Codeforces Round #284 (Div. 1) C. Array and Operations 二分图最大匹配
题目链接: http://codeforces.com/problemset/problem/498/C C. Array and Operations time limit per test1 se ...
- Codeforces Round #284 (Div. 2) C题(计算几何)解题报告
题目地址 简要题意: 给出两个点的坐标,以及一些一般直线方程Ax+B+C=0的A.B.C,这些直线作为街道,求从一点走到另一点需要跨越的街道数.(两点都不在街道上) 思路分析: 从一点到另一点必须要跨 ...
- Codeforces Round #284 (Div. 1)
A. Crazy Town 这一题只需要考虑是否经过所给的线,如果起点和终点都在其中一条线的一侧,那么很明显从起点走点终点是不需要穿过这条线的,否则则一定要经过这条线,并且步数+1.用叉积判断即可. ...
- Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配
因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...
- Codeforces Round #284 (Div. 2) D. Name That Tune [概率dp]
D. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #284 (Div. 1) B. Name That Tune(概率DP)(难)
B. Name That Tune time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #284 (Div. 2) A
解题思路:给出 n个电影的精彩时段(a[i],b[i]),和每次可以跳过的时间x,问要看完所有的精彩时刻,至少需要看多长时间的电影. 因为要时间最少,所有除了精彩时刻的电影则能跳过就跳过(用取余来算) ...
随机推荐
- SQL中迁移sql用户及密码脚本
SQL中迁移sql用户及密码脚本 编写人:CC阿爸 2014-6-20 在日常SQL数据库的操作中,常常需要迁移数据库或重装服务器,这时候,一些之前建立的login账户,必须重新建立,以下可以通过 ...
- shell字符串操作详解
shell字符串操作详解的相关资料. 1.shell变量声明的判断 表达式 含义 ${var} 变量var的值, 与$var相同 ${var-DEFAULT} 如果var没有被声明, 那么就以$DE ...
- shopnc二次开发(一)
---恢复内容开始--- 以前没有怎么接触过shopnc,感觉界面挺漂亮的,不过后来自己需要开发一个电商系统,就顺便参考了下,感觉构架垃圾的一塌糊涂.不过平时做这个系统二次开发的业务比较多,所以简单的 ...
- HOOK API 在多线程时应该注意的问题点
在使用INLINE HOOK API实现对系统API的拦截时,正常情况下并没有太大问题,但一旦涉及到多线程,不管是修改IAT还是JMP,2种方法均会出现不可预料的问题,特别是在HOOK一些复杂的大型系 ...
- ajax使用。
<script> function createAjax(){ var request=false; //window对象中有XMLHttpRequest存在就是非IE,包括(IE7,IE ...
- [重点翻译] ASP.NET 4.6的更新 -- 本文只摘录 Web Forms的部分
原文出处:[重点翻译] ASP.NET 4.6的更新 -- 本文只摘录 Web Forms的部分 http://www.dotblogs.com.tw/mis2000lab/archive/2015/ ...
- for xml path('') 引发的数据不完整
When you read Extensible Markup Language (XML) data from Microsoft SQL Server by using the SqlDataRe ...
- MVC MVVM Knockout 常遇问题总结
1.模板绑定(使用插件jquery.tmpl) var ViewModel={Product:ko.observable()} <div data-bind="template:{na ...
- scrapy爬虫框架入门教程
scrapy安装请参考:安装指南. 我们将使用开放目录项目(dmoz)作为抓取的例子. 这篇入门教程将引导你完成如下任务: 创建一个新的Scrapy项目 定义提取的Item 写一个Spider用来爬行 ...
- masterha_check_repl报错汇总
[root@DBMysql ~]#masterha_check_repl --conf=/etc/masterha/app1.cnf 导致如下报错的原因主要有两类: 1.mysql的安装时用源码安装, ...