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,问要看完所有的精彩时刻,至少需要看多长时间的电影. 因为要时间最少,所有除了精彩时刻的电影则能跳过就跳过(用取余来算) ...
随机推荐
- [Java]_函数传参的疑惑与思考
问题来源于leetcode上的两道题 Path Sum I && II,分别写了两个dfs. void dfs(TreeNode node , int sum , ArrayList& ...
- [leetcode]_Merge Sorted Array
题目:合并两个有序数组A , B,将合并后的数组存到A中.假设A的空间足够装下A和B所有的元素. 思路:这道题考虑如果正向扫描两个数组,则每插入一个元素,则需移动A后的所有元素.换个角度想,既然元素个 ...
- 使用maven, myeclipse工具构建spring mvc项目
一.使用myeclipse 创建一个新的 maven项目. (ps:1.在filter过滤的时候输入 webapp 选择"maven-archetype-webapp". 2.在m ...
- PHP二维数组根据某个键名排序
$result = array( array( "amount": "11.00", "date": ...
- SQLite数据库管理的相关命令
1.创建数据库 启动命令行,通过输入如下命令打开Shell模式的CLP: sqlite3 test.db 虽然我们提供了数据库名称,但如果该数据库不存在,SQLite实际上就未创建该数据库,直到在数据 ...
- 04-树5 Root of AVL Tree
平衡二叉树 LL RR LR RL 注意画图理解法 An AVL tree is a self-balancing binary search tree. In an AVL tree, the he ...
- zip压缩
package com.green.project.compress; import java.io.File;import java.io.FileInputStream;import java.i ...
- Eclipse基金会
昨天Eclipse基金会庆祝其成立十周年.2004年2月的新闻稿宣布该非盈利组织的正式成立,由包括开发者.消费者和插件提供商在内的各独立团体组成的董事会,为Eclipse的长期发展负责. 基金会成立时 ...
- iOS中MVC设计模式
在组织大型项目的代码文件时,我们常用MVC的思想.MVC的概念讲起来非常简单,就和对象(object)一样.但是理解和应用起来却非常困难.今天我们就简单总结一下MVC设计理念. MVC(Model V ...
- WordPress实现长篇文章/日志/单页面分页功能效果
在WordPress里写文章,如果内容很多,你可能想要把文章分成几页来让访客浏览,这样既保持了网页的美观,也提高了网页的打开速度.但是在WordPress默认提供的按钮里,你可能找不到文章分页功能所对 ...