http://poj.org/problem?id=2785
2018-04-04 19:18
204 查看
点击打开链接
啊 刚刚写好的 博客 手残 点错了 就没有了 只能从新打一遍了 啊~~ 这个题的大意就是 让我们 找四个数 能不能 直接相加等于0
这个我的思路是 两两相加 然后一个 直接赋值为相反数 然后一个sort排序 直接 二分 就行 听说这个暴力 也能过 #include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
int a[5000],b[5000],c[5000],d[5000];
int s[25000010],x[25000010];
int t,g=0,gg=0,sum=0;
int jd(int xx)
{
int l=0,r=g,mid;
int w,v;
while(l<=r)
{
mid=(l+r)/2;
if(x[xx]==s[mid])
{ v=1;
w=mid-1;
while(w>=0&&x[xx]==s[w])
v++,w--;
w=mid+1;
while(w<g&&x[xx]==s[w])
v++,w++;
return v;
}
else if(x[xx]<s[mid])
{
r=mid-1;
}
else
l=mid+1;
}
return 0;
}
int main()
{
scanf("%d",&t);
for(int i=0;i<t;i++)
scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
for(int i=0;i<t;i++)
{
for(int j=0;j<t;j++)
{
s[g++]=a[i]+b[j];
x[gg++]=-(c[i]+d[j]);
}
}
sort(s,s+g);
for(int i=0;i<g;i++)
sum+=jd(i);
printf("%d\n",sum);
return 0;
}
啊 刚刚写好的 博客 手残 点错了 就没有了 只能从新打一遍了 啊~~ 这个题的大意就是 让我们 找四个数 能不能 直接相加等于0
这个我的思路是 两两相加 然后一个 直接赋值为相反数 然后一个sort排序 直接 二分 就行 听说这个暴力 也能过 #include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;
int a[5000],b[5000],c[5000],d[5000];
int s[25000010],x[25000010];
int t,g=0,gg=0,sum=0;
int jd(int xx)
{
int l=0,r=g,mid;
int w,v;
while(l<=r)
{
mid=(l+r)/2;
if(x[xx]==s[mid])
{ v=1;
w=mid-1;
while(w>=0&&x[xx]==s[w])
v++,w--;
w=mid+1;
while(w<g&&x[xx]==s[w])
v++,w++;
return v;
}
else if(x[xx]<s[mid])
{
r=mid-1;
}
else
l=mid+1;
}
return 0;
}
int main()
{
scanf("%d",&t);
for(int i=0;i<t;i++)
scanf("%d%d%d%d",a+i,b+i,c+i,d+i);
for(int i=0;i<t;i++)
{
for(int j=0;j<t;j++)
{
s[g++]=a[i]+b[j];
x[gg++]=-(c[i]+d[j]);
}
}
sort(s,s+g);
for(int i=0;i<g;i++)
sum+=jd(i);
printf("%d\n",sum);
return 0;
}
相关文章推荐
- poj 1679 http://poj.org/problem?id=1679
- POJ1742Coinshttp://poj.org/problem?id=1742
- poj2001 http://poj.org/problem?id=2001 简单的字典树题目
- http://poj.org/problem?id=1961
- http://poj.org/problem?id=2488
- http://poj.org/problem?id=3624
- http://poj.org/problem?id=1252
- http://poj.org/problem;jsessionid=57CE7F39567FF9BFA128CDB4A2E8D728?id=2553
- Dungeon Master&&http://poj.org/problem?id=2251
- 2-sat&&http://poj.org/problem?id=3648
- http://poj.org/problem?id=3781&&Nth Largest Value
- poj 1061 青蛙的约会 二元一次不定方程 http://poj.org/problem?id=1061
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=3159
- poj 1915 http://poj.org/problem?id=1915
- POJ3278http://poj.org/problem?id=3278
- http://poj.org/problem?id=1376
- http://poj.org/problem?id=1861&&Kursal
- http://poj.org/problem?id=1840
- poj 1061 青蛙的约会 二元一次不定方程 http://poj.org/problem?id=1061