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,问要看完所有的精彩时刻,至少需要看多长时间的电影. 因为要时间最少,所有除了精彩时刻的电影则能跳过就跳过(用取余来算) ...
随机推荐
- DevExpress 重编译 替换强命名 修改源码
本文以DevExpress 11.1.8举例 必须满足几个条件 1. 必须有DXperience相应版本的全部源代码SourceCode.把全部源代码复制到X:\Program Files\DevEx ...
- 关于js中this的疑问
学习bootstrap.js源码中被js里边的this绕的有点晕 /* ================================================================ ...
- .Net 自己写个简单的 半 ORM (练手)
ORM 大家都知道, .Net 是EF 还有一些其他的ORM 从JAVA 中移植过来的 有 , 大神自己写的也有 不管ORM 提供什么附加的 乱七八糟的功能 但是 最主要的 还是 关系映射 的事情 ...
- jquery Mobile应用第2课《构建跨平台APP:jQuery Mobile移动应用实战》连载二(简单的QWER键盘)
在jQuery Mobile的布局中,控件大多都是单独占据页面中的一行,按钮自然也不例外,但是仍然有一些方法能够让多个按钮组成一行,比如说在范例6-5中就利用按钮分组的方法使4个按钮并列在一行中,如图 ...
- (转)Android网络命令
转自:http://www.cnblogs.com/shunyao8210/archive/2010/08/10/1796214.html ifconfig 1. 作用 ifconfig用 ...
- Java 需要记得、了解的关键词 (Java 学习中的小记录)
Java 需要记得.了解的关键词 (Java 学习中的小记录) 作者:王可利(Star·星星) 总结:本次随笔,仅且拿来平时翻阅记忆用
- Java实现多线程邮件发送
利用java多线程技术配合线程池实现多任务邮件发送. 1.基本邮件发送MailSender package hk.buttonwood.ops.email; import java.io.File; ...
- SQL Server基本操作积累
一.基本操作 1.将数据绑定到DataGridVirw控件上显示的数据列标题将会是数据库中的字段名称,可以在使用select语句时使用AS关键字将转化为列名的别名 select name AS 姓名 ...
- golang的"..."备忘
1. 用于数组: 表示长度与元素个数相同. 在golang中数组的长度是类型的一部分,不同长度,不同类型. 2. 用于参数: 用于形参表示可变参数. 用于实参表示直接传递. 具体解释参数见官方文档: ...
- golang的序列与反序列化
golang写backend之类的应用,还是挺方便的...使用encoding/json包时, 必须注意, 在struct定义的属性必须是exported, 否则不会设置值. 例如:type DRol ...