10574 - Counting Rectangles

Problem H

Counting Rectangles

Input: Standard Input

Output: Standard Output

Time Limit: 3 Seconds

 

Given n points on the XY plane, count how many regular rectangles are formed. A rectangle is regular if and only if its sides are all parallel to the axis.

 

Input

The first line contains the number of tests t(1<=t<=10). Each case contains a single line with a positive integer n(1<=n<=5000), the number of points. There are n lines follow, each line contains 2 integers x(0<=xy<=109) indicating the coordinates of a point.

 

Output

For each test case, print the case number and a single integer, the number of regular rectangles found.

 

Sample Input                             Output for Sample Input

2

5

0 0

2 0

0 2

2 2

1 1

3

0 0

0 30

0 900

Case 1: 1

Case 2: 0


Problemsetter: Rujia Liu, Member of Elite Problemsetters' Panel

Special Thanks: IOI2003 China National Training Team

 

思路:首先将x坐标和y坐标离散化一下....然后就开始直接乱搞了...有人n^2枚举对角线就可以了。 我的麻烦一些咯。


代码:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <map>
#include <set>
#include <stdio.h>
#include <cmath>
#include <cassert>
#include <math.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,b,a) for(int i = (b); i >= (a); --i)
#define clr(a,x) memset(a,(x),sizeof(a))
#define LL long long
#define eps 1e-9
#define mp make_pair
using namespace std;
const int maxn = 5000 + 5;
int n;
struct Point
{
    int x,y;
    bool operator < (const Point & pt) const
    {
        if (x != pt.x) return x < pt.x;
        return y < pt.y;
    }
}pt[maxn];

bool vis[maxn][maxn];

vector<int> line[maxn];

void input()
{
    scanf("%d",&n);
    rep(i,0,n) scanf("%d%d",&pt[i].x,&pt[i].y);
    sort(pt,pt+n);
    vector<int> v;
    rep(i,0,n) {
        v.push_back(pt[i].x);
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    rep(i,0,n) {
        pt[i].x = lower_bound(v.begin(),v.end(),pt[i].x) - v.begin();

    }
    v.clear();
    rep(i,0,n) v.push_back(pt[i].y);
    sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
    rep(i,0,n) pt[i].y = lower_bound(v.begin(),v.end(),pt[i].y) - v.begin();
    rep(i,0,n) vis[pt[i].x][pt[i].y] = true;

    rep(i,0,n+1) line[i].clear();
    rep(i,0,n) line[pt[i].x].push_back(i);
}

bool visy[maxn];
vector<int> vx[maxn];

void solve()
{
    int sz = 0;
    clr(visy,0);
    rep(i,0,maxn) vx[i].clear();
    rep(i,0,n) {
        if (line[i].empty()) break;
        sz++;
    }
    vector<int> * v;
    int ans = 0;
    int a,y1,b,y2;
    rrep(w,sz-1,0) {
        rep(i,0,line[w].size()) {
            a = line[w][i];
            y1 = pt[a].y;
            if (!visy[y1]) continue;
            rep(j,i+1,line[w].size()) {
                b = line[w][j];
                y2 = pt[b].y;
                if (!visy[y2]) continue;
                if (vx[y1].size() < vx[y2].size()) v = &vx[y1];
                else v = &vx[y2];
                for(auto it = v->begin(); it != v->end(); ++it) {
                    if (vis[*it][y1] && vis[*it][y2]) ++ans;
                }
            }
        }
        rep(i,0,line[w].size()) {
            int y = pt[line[w][i]].y;
            vx[y].push_back(w);
            visy[y] = true;
        }
    }
    printf("%d\n",ans);
    rep(i,0,n) {
        int x = pt[i].x, y = pt[i].y;
        vis[x][y] = false;
    }
}

void Getinput()
{
    freopen("in.txt","w",stdout);
    int T = 1;
    printf("%d\n",T);
    while (T--) {
        int n = 5000;
        printf("%d\n",n);
        rep(i,0,n/2) printf("%d %d\n",0,i);
        rep(i,0,n-n/2) printf("1 %d\n",i);
    }
}

int main()
{
   //Getinput(); return 0;
    #ifdef ACM
        freopen("in.txt", "r", stdin);
       // freopen("out.txt","w",stdout);
    #endif // ACM
    int T; cin >> T;
    rep(cas,1,T+1) {
        input();
        printf("Case %d: ",cas);
        solve();
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!对于复现VQA-Counting模型,您可以按照以下步骤进行操作: 1. 数据集准备:首先,您需要准备VQA-Counting数据集。该数据集通常包含图像、问题以及答案。您可以在VQA官方网站或者其他开源数据集库中找到该数据集。确保将数据集分成训练集、验证集和测试集。 2. 模型选择:选择适合的模型来解决VQA-Counting任务。常见的模型包括基于深度学习的视觉问答模型,如VGGNet、ResNet等。您可以选择现有的基于视觉问答的模型,并根据需要进行修改。 3. 模型训练:使用训练集中的图像、问题和答案,对所选模型进行训练。在训练过程中,您可以使用图像特征提取器来提取图像特征,并将其与问题特征进行融合。然后,根据融合后的特征预测答案中存在的对象数量。 4. 模型评估:使用验证集对训练好的模型进行评估。通过计算预测答案与真实答案之间的误差或准确性指标来评估模型的性能。您可以使用常见的评估指标,如准确率、均方根误差等。 5. 模型调优:根据评估结果,您可以调整模型的超参数或结构,以进一步提高模型的性能。可以尝试不同的优化算法、学习率、批次大小等参数来优化模型。 6. 模型测试:在测试集上进行模型测试,并计算模型的最终性能指标。确保在测试集上的性能与验证集上的性能相当,以验证模型的泛化能力。 请注意,以上提到的步骤仅为一般建议,具体实现会因您选择的模型和数据集而有所不同。此外,复现VQA-Counting模型可能需要较大的计算资源和时间,因此您需要进行必要的准备。 希望这些步骤对您有所帮助!如果您有任何进一步的问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值