Codeforces Round #284 (Div. 2) A B C

A - Watching a movie :看电影,每个镜头从li ~ ri 且保证 li+1 > ri。每次能跳过X分钟,问从第一分钟开始看起看完所有时间需要多少时间。

注意第i分钟看完电影放到第i+1分钟就好了。

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

int main()
{
    int n, x;
    int l, r;
    int now;
    while(~scanf("%d%d", &n, &x))
    {
        now = 1;
        int ans = 0;
        while(n--)
        {
            scanf("%d%d", &l, &r);
            while( now + x <= l )
                now += x;
            ans += (r - now + 1);
            now = r+1;
        }
        
        printf("%d\n", ans);
    }
    return 0;
}

B - Lecture:给出第一语言和第二语言一一对应的关系,再给出老师上课给出的语言单词(第一语言),问你记录的单词是什么。(记录的规则是相同长度取第一语言,否则取较短的那个)

#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
#include<iostream>

using namespace std;

map<string, string> mp;

int n, m;

int main()
{
    cin.sync_with_stdio(0);
    while( cin >> m >> n )
    {
        mp.clear();
        string z, x;
        while(n--)
        {
            cin >> z >> x;
            mp[z] = x;
            mp[x] = z;
        }
        cin >> x;
        m--;
        z = mp[x];
        if( z.length() >= x.length() )
            cout << x;
        else if( z.length() < x.length() )
            cout << z;
        while(m--)
        {
            cin >> x;
            z = mp[x];
            if( z.length() >= x.length() )
                cout << " " << x;
            else if( z.length() < x.length() )
                cout << " " << z;
        }
        cout << endl;
    }
    return 0;
}

C - Crazy Town :n条直线把空间分割成多个区域,给出起点和终点所在的区域,问从起点到终点需要多少步(两个区域公用同一个边才能算相邻)

问题转化为,因为每次从区域1走到区域2,需要穿过1条线,那么判断最少需要穿过多少条线,得到的就是结果了。

#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

typedef __int64 ll;

ll a, b, c;
ll z, x, zz, xx;

int main()
{
	while(~scanf("%I64d %I64d", &z, &x))
	{
		scanf("%I64d %I64d", &zz, &xx);
		int n, ans = 0;
		scanf("%d", &n);
		while(n--)
		{
			scanf("%I64d %I64d %I64d", &a, &b, &c);
			//if( (a*z + b*x + c) * (a*zz + b*xx + c) < 0)//乘法中间会溢出 
			int cc = (a*z + b*x + c) > 0 ? 1 : -1;
			int d = (a*zz + b*xx + c) > 0 ? 1 : -1;
			if( cc != d )
				ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值