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;
}