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,问要看完所有的精彩时刻,至少需要看多长时间的电影. 因为要时间最少,所有除了精彩时刻的电影则能跳过就跳过(用取余来算) ...
随机推荐
- PHPExcel上传sae遇到: -1:fail to get xml content
在用PHPExcel1.8.0来处理excel时,本地测试时好使的,但是要把代码部署到SAE,在上传代码的时候就会遇到这个问题. 部署代码中遇到问题: -1:fail to get xml conte ...
- HTML5开发规范
1.总体规范——采用html5的结构标签进行页面布局,注意结构的语义化,并注意页面大纲的层级结构.使用css3.0进行样式的设计. a.网页大纲查询网址http://gsnedders.html5.o ...
- js控制文本框只能输入数字 及 常用字符对应ASCII码值
方法一: <INPUT TYPE='text' NAME=text onkeypress="a()"><script language=javascript> ...
- asp.net解析请求报文
NameValueCollection myHeader = new NameValueCollection(); int i; string strKey; string result; myHea ...
- 批量kill进程
ps -e | grep java |awk '{print $1}'|xargs kill -9
- Eclipse 4.6 Neon, could not create the java virtual machine
下了eclipse 4.6,打开报错:could not create the java virtual machine. a fatal exception has occurred. 命令行用 e ...
- 5.html5中的路径表示
路径在html中的作用主要是进行外部资源的引入,如css文件,js文件,媒体文件等. 而路径本身有分为相对路径和绝对路径.所谓相对路径,就是相对于链接页面而言的另一个页面的路径.而绝对路径,就是直接从 ...
- 2.css选择器
由第一节的语法结构可以看出css语言的核心思想就是:找到对象,然后对选定的对象进行属性赋值.其中,css中对象的选择,依靠的就是选择器.当掌握了选择器以后,就能够指哪打哪,弹无虚发了. css的选择器 ...
- 编译mgiza的准备
cmake之前需要首先设置环境变量: export BOOST_LIBRARYDIR=$BOOST_ROOT/lib64export BOOST_ROOT=/home/noah/boost_1_57_ ...
- SSH使用缩写
需要经常ssh到其它机器上,但如果每次都使用主机命名或ip地址,那挺难受的.这里有2个方法可以在ssh登陆时缩写(简写)主机名. 1. 在~/.ssh中添加config文件 [toughhou@hd1 ...