矩阵中不重复的元素(51Nod-1024)

题目

一个m*n的矩阵。

该矩阵的第一列是a^b,(a+1)^b,.....(a + n - 1)^b
第二列是a^(b+1),(a+1)^(b+1),.....(a + n - 1)^(b+1)
.......
第m列是a^(b + m - 1),(a+1)^(b + m - 1),.....(a + n - 1)^(b + m - 1)
(a^b表示a的b次方)

下面是一个4*4的矩阵:

2^2=4, 2^3=8, 2^4=16, 2^5=32
3^2=9, 3^3=27, 3^4=81, 3^5=243
4^2=16, 4^3=64, 4^4=256, 4^5=1024
5^2=25, 5^3=125, 5^4=625, 5^5=3125

问这个矩阵里有多少不重复的数(比如4^3 = 8^2,这样的话就有重复了)

2^2=4, 2^3=8, 2^4=16, 2^5=32
3^2=9, 3^3=27, 3^4=81, 3^5=243
4^2=16, 4^3=64, 4^4=256, 4^5=1024

m = 4, n = 3, a = 2, b = 2。其中2^4与4^2是重复的元素。

输入

输入数据包括4个数:m,n,a,b。中间用空格分隔。m,n为矩阵的长和宽(2 <= m,n <= 100)。a,b为矩阵的第1个元素,a^b(2 <= a , b <= 100)。

输出

输出不重复元素的数量。

输入样例

4 3 2 2

输出样例

11

思路:使用 set 然后暴力即可

源程序

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define E 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD=7;
const int N=50000+5;
const int dx[]= {-1,1,0,0};
const int dy[]= {0,0,-1,1};
using namespace std;

int main(){
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    set< pair<int,int> > s;
    for(int i=0;i<m;++i){//行
        int temp=a+i;
        for(int j=0;j<n;++j){//列
            if(temp==4)
                s.insert(make_pair(2,(b+j)*2));
            else if(temp==8)
                s.insert(make_pair(2,(b+j)*3));
            else if(temp==16)
                s.insert(make_pair(2,(b+j)*4));
            else if(temp==32)
                s.insert(make_pair(2,(b+j)*5));
            else if(temp==64)
                s.insert(make_pair(2,(b+j)*6));
            else if(temp==128)
                s.insert(make_pair(2,(b+j)*7));
            else if(temp==9)
                s.insert(make_pair(3,(b+j)*2));
            else if(temp==27)
                s.insert(make_pair(3,(b+j)*3));
            else if(temp==81)
                s.insert(make_pair(3,(b+j)*4));
            else if(temp==25)
                s.insert(make_pair(5,(b+j)*2));
            else if(temp==125)
                s.insert(make_pair(5,(b+j)*3));
            else if(temp==36)
                s.insert(make_pair(6,(b+j)*2));
            else if(temp==49)
                s.insert(make_pair(7,(b+j)*2));
            else if(temp==100)
                s.insert(make_pair(10,(b+j)*2));
            else if(temp==121)
                s.insert(make_pair(11,(b+j)*2));
            else if(temp==144)
                s.insert(make_pair(12,(b+j)*2));
            else if(temp==169)
                s.insert(make_pair(13,(b+j)*2));
            else if(temp==196)
                s.insert(make_pair(14,(b+j)*2));
            else
                s.insert(make_pair(temp,b+j));
        }
    }
    cout<<s.size()<<endl;
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值