ccf-201809-2 涔拌彍
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ccf-201809-2 涔拌彍相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/return' title='return'>return
main 闂 space 鏁版嵁 瑙勬ā names end pre闂鎻忚堪
銆€銆€灏廐鍜屽皬W鏉ュ埌浜嗕竴鏉¤涓婏紝涓や汉鍒嗗紑涔拌彍锛屼粬浠拱鑿滅殑杩囩▼鍙互鎻忚堪涓猴紝鍘诲簵閲屼拱涓€浜涜彍鐒跺悗鍘绘梺杈圭殑涓€涓箍鍦烘妸鑿滆涓婅溅锛屼袱浜洪兘瑕佷拱n绉嶈彍锛屾墍浠ヤ篃閮借瑁卬娆¤溅銆傚叿浣撶殑锛屽浜庡皬H鏉ヨ鏈塶涓笉鐩镐氦鐨勬椂闂存[a1,b1],[a2,b2]...[an,bn]鍦ㄨ杞︼紝瀵逛簬灏廤鏉ヨ鏈塶涓笉鐩镐氦鐨勬椂闂存[c1,d1],[c2,d2]...[cn,dn]鍦ㄨ杞︺€傚叾涓紝涓€涓椂闂存[s, t]琛ㄧず鐨勬槸浠庢椂鍒籹鍒版椂鍒籺杩欐鏃堕棿锛屾椂闀夸负t-s銆?br />
銆€銆€鐢变簬浠栦滑鏄ソ鏈嬪弸锛屼粬浠兘鍦ㄥ箍鍦轰笂瑁呰溅鐨勬椂鍊欎細鑱婂ぉ锛屼粬浠兂鐭ラ亾浠栦滑鍙互鑱婂闀挎椂闂淬€?br />
杈撳叆鏍煎紡
銆€銆€杈撳叆鐨勭涓€琛屽寘鍚竴涓鏁存暟n锛岃〃绀烘椂闂存鐨勬暟閲忋€?br />
銆€銆€鎺ヤ笅鏉琛屾瘡琛屼袱涓暟ai锛宐i锛屾弿杩板皬H鐨勫悇涓杞︾殑鏃堕棿娈点€?br />
銆€銆€鎺ヤ笅鏉琛屾瘡琛屼袱涓暟ci锛宒i锛屾弿杩板皬W鐨勫悇涓杞︾殑鏃堕棿娈点€?br />
杈撳嚭鏍煎紡
銆€銆€杈撳嚭涓€琛岋紝涓€涓鏁存暟锛岃〃绀轰袱浜哄彲浠ヨ亰澶氶暱鏃堕棿銆?br />
鏍蜂緥杈撳叆
4
1 3
5 6
9 13
14 15
2 4
5 7
10 11
13 14
鏍蜂緥杈撳嚭
3
鏁版嵁瑙勬ā鍜岀害瀹?br />
銆€銆€瀵逛簬鎵€鏈夌殑璇勬祴鐢ㄤ緥锛? 鈮?n 鈮?2000, ai < bi < ai+1锛宑i < di < ci+1,瀵逛簬鎵€鏈夌殑i(1 鈮?i 鈮?n)鏈夛紝1 鈮?ai, bi, ci, di 鈮?1000000銆?/p>
#include <iostream>
using namespace std;
struct per{
long long left;
long long right;
};
per a[2001];
per b[2001];
int main()
{
int n;
long long time = 0;
long long left,right;
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i].left;
cin >> a[i].right;
}
for(int i = 1;i <= n;i++)
{
cin >> b[i].left;
cin >> b[i].right;
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= n;j++)
{
if(a[i].left >= b[j].right)
{
continue;
}
else if(a[i].right <= b[j].left)
{
break;
}
else
{
if(a[i].left > b[j].left)
{
left = a[i].left;
}
else
{
left = b[j].left;
}
if(a[i].right < b[j].right)
{
right = a[i].right;
}
else
{
right = b[j].right;
}
time += right - left;
}
}
}
cout << time << endl;
return 0;
}
以上是关于ccf-201809-2 涔拌彍的主要内容,如果未能解决你的问题,请参考以下文章