MyException - 我的异常网
当前位置:我的异常网» 编程 » Codeforces Round #284 (Div. 二)

Codeforces Round #284 (Div. 二)

www.MyException.Cn  网友分享于:2014-12-27  浏览:0次
Codeforces Round #284 (Div. 2)

http://codeforces.com/contest/499


A

 

A. Watching a movie
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have decided to watch the best moments of some movie. There are two buttons on your player:

  1. 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.
  2. 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?

Input

The first line contains two space-separated integers nx (1 ≤ n ≤ 501 ≤ x ≤ 105) — the number of the best moments of the movie and the value of x for the second button.

The following n lines contain the descriptions of the best moments of the movie, the i-th line of the description contains two integers separated by a space liri (1 ≤ li ≤ ri ≤ 105).

It is guaranteed that for all integers i from 2 to n the following condition holds: ri - 1 < li.

Output

Output a single number — the answer to the problem.

Sample test(s)
input
2 3
5 6
10 12
output
6
input
1 1
1 100000
output
100000
Note

In the first sample, the player was initially standing on the first minute. As the minutes from the 1-st to the 4-th one don't contain interesting moments, we press the second button. Now we can not press the second button and skip 3 more minutes, because some of them contain interesting moments. Therefore, we watch the movie from the 4-th to the 6-th minute, after that the current time is 7. Similarly, we again skip 3 minutes and then watch from the 10-th to the 12-th minute of the movie. In total, we watch 6 minutes of the movie.

In the second sample, the movie is very interesting, so you'll have to watch all 100000 minutes of the movie.

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <queue>

using namespace std;

struct
{
    int s;
    int e;
}p[55];

int n,x;

int main()
{
    while (scanf("%d %d", &n,&x) != EOF)
    {
        for (int i = 1; i <= n; i++)
        {
            scanf("%d %d",&p[i].s,&p[i].e);
        }
        int pos = 1;
        int ans = 0;

        for (int i = 1; i <= n; i++)
        {
            ans += ( p[i].s - pos ) % x;
            ans += p[i].e - p[i].s+1;
            pos = p[i].e + 1;
        }
        printf("%d\n",ans);
    }
    return 0;
}

B. Lecture
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains two integers, n and m (1 ≤ n ≤ 30001 ≤ m ≤ 3000) — the number of words in the professor's lecture and the number of words in each of these languages.

The following m lines contain the words. The i-th line contains two strings aibi meaning that the word ai belongs to the first language, the word bi belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once.

The next line contains n space-separated strings c1, c2, ..., cn — the text of the lecture. It is guaranteed that each of the strings cibelongs to the set of strings {a1, a2, ... am}.

All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.

Output

Output exactly n words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.

Sample test(s)
input
4 3
codeforces codesecrof
contest round
letter message
codeforces contest letter contest
output
codeforces round letter round
input
5 3
joll wuqrd
euzf un
hbnyiyc rsoqqveh
hbnyiyc joll joll euzf joll
output
hbnyiyc joll joll un joll

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;

struct
{
    char s[10000];
    char e[10000];
}p[10000];

int main()
{
    int n, m;
    while (scanf("%d %d", &n, &m) != EOF)
    {
        
        for (int i = 1; i <= m; i++)
        {
            scanf("%s %s",p[i].s,p[i].e);
            int l1 = strlen(p[i].s);
            int l2 = strlen(p[i].e);
            if (l1 > l2)
            {
                char c[10000];
                strcpy(c,p[i].s);
                strcpy(p[i].s, p[i].e);
                strcpy(p[i].e, c);
            }
        }
        for (int i = 1; i <= n; i++)
        {
            char c[10000];
            scanf("%s",c);
            for (int j = 1; j <= m; j++)
            {
                if ( !strcmp(p[j].e, c) || !strcmp(p[j].s, c))
                {
                    if (i == n)
                    {
                        printf("%s\n", p[j].s);
                    }
                    else
                    {
                        printf("%s ",p[j].s);
                    }
                    break;
                }
            }
        }
    }
    return 0;
}



C. Crazy Town
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains two space-separated integers x1y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.

The second line contains two integers separated by a space x2y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.

The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106|ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

Output

Output the answer to the problem.

Sample test(s)
input
1 1
-1 -1
2
0 1 0
1 0 0
output
2
input
1 1
-1 -1
3
1 0 0
0 1 0
1 1 -3
output
2
Note

Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):


带入两点, 判断使两点值符号不同直线有多少个,

不要直接判断 ,long long 不够存


#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<time.h>
#include<utility> 
#include<malloc.h> 

using namespace std;

long long  sx, sy, ex, ey;
int n;

int main()
{
		cin >> sx >> sy;
		cin >> ex >> ey;
		cin >> n;
		int ans = 0;
		while (n--)
		{
			long long a, b, c;

			cin >> a >> b >> c;
			int f1 = (sx * a + sy * b + c) > 0 ? 1 : 0;
			int f2 = (ex * a + ey * b + c) > 0 ? 1 : 0;
			if (f1 != f2)
			{
				ans++;
			}
		}
		cout << ans << endl;
	return 0;
}





文章评论

 程序员的样子
程序员的样子
Web开发人员为什么越来越懒了?
Web开发人员为什么越来越懒了?
10个帮程序员减压放松的网站
10个帮程序员减压放松的网站
老美怎么看待阿里赴美上市
老美怎么看待阿里赴美上市
为啥Android手机总会越用越慢?
为啥Android手机总会越用越慢?
初级 vs 高级开发者 哪个性价比更高?
初级 vs 高级开发者 哪个性价比更高?
程序员周末都喜欢做什么?
程序员周末都喜欢做什么?
看13位CEO、创始人和高管如何提高工作效率
看13位CEO、创始人和高管如何提高工作效率
亲爱的项目经理,我恨你
亲爱的项目经理,我恨你
编程语言是女人
编程语言是女人
10个调试和排错的小建议
10个调试和排错的小建议
如何区分一个程序员是“老手“还是“新手“?
如何区分一个程序员是“老手“还是“新手“?
我跳槽是因为他们的显示器更大
我跳槽是因为他们的显示器更大
鲜为人知的编程真相
鲜为人知的编程真相
旅行,写作,编程
旅行,写作,编程
程序员和编码员之间的区别
程序员和编码员之间的区别
2013年美国开发者薪资调查报告
2013年美国开发者薪资调查报告
团队中“技术大拿”并非越多越好
团队中“技术大拿”并非越多越好
老程序员的下场
老程序员的下场
Google伦敦新总部 犹如星级庄园
Google伦敦新总部 犹如星级庄园
Java 与 .NET 的平台发展之争
Java 与 .NET 的平台发展之争
程序员最害怕的5件事 你中招了吗?
程序员最害怕的5件事 你中招了吗?
Java程序员必看电影
Java程序员必看电影
程序员必看的十大电影
程序员必看的十大电影
程序员的一天:一寸光阴一寸金
程序员的一天:一寸光阴一寸金
程序员眼里IE浏览器是什么样的
程序员眼里IE浏览器是什么样的
Web开发者需具备的8个好习惯
Web开发者需具备的8个好习惯
那些争议最大的编程观点
那些争议最大的编程观点
我是如何打败拖延症的
我是如何打败拖延症的
聊聊HTTPS和SSL/TLS协议
聊聊HTTPS和SSL/TLS协议
总结2014中国互联网十大段子
总结2014中国互联网十大段子
如何成为一名黑客
如何成为一名黑客
代码女神横空出世
代码女神横空出世
中美印日四国程序员比较
中美印日四国程序员比较
5款最佳正则表达式编辑调试器
5款最佳正则表达式编辑调试器
每天工作4小时的程序员
每天工作4小时的程序员
做程序猿的老婆应该注意的一些事情
做程序猿的老婆应该注意的一些事情
什么才是优秀的用户界面设计
什么才是优秀的用户界面设计
十大编程算法助程序员走上高手之路
十大编程算法助程序员走上高手之路
程序员应该关注的一些事儿
程序员应该关注的一些事儿
当下全球最炙手可热的八位少年创业者
当下全球最炙手可热的八位少年创业者
“肮脏的”IT工作排行榜
“肮脏的”IT工作排行榜
要嫁就嫁程序猿—钱多话少死的早
要嫁就嫁程序猿—钱多话少死的早
60个开发者不容错过的免费资源库
60个开发者不容错过的免费资源库
漫画:程序员的工作
漫画:程序员的工作
程序猿的崛起——Growth Hacker
程序猿的崛起——Growth Hacker
2013年中国软件开发者薪资调查报告
2013年中国软件开发者薪资调查报告
我的丈夫是个程序员
我的丈夫是个程序员
写给自己也写给你 自己到底该何去何从
写给自己也写给你 自己到底该何去何从
软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有