wikioi 1553 互斥的數

2021-06-25 10:23:54 字數 1476 閱讀 9560

題目大意:

給定n 和 p, 

規則 :if(x == y * p) 那麼x 與 y 互斥。

找出最大的集合,每個元素兩兩不互斥。

思路:既然x * p 和 y 互斥,那麼,如果有a[i] 滿足a[i] * p 和 a[i] 互斥,就刪掉a[i] * p。

因為如果刪除a[i] * p , 會使a[i] * p * p 可以存在於集合中,所以刪a[i] * p 一定不會比刪a[i] 差。

因為要保證刪除的時候能夠刪除a[i] * p, 所以把元素從小到大排一遍序。

要保證查詢的效率,用雜湊進行離散化(當然set也行)。

code:

#include#include#include#include#include#include#include#include#include#include#include#include#include#include#define ll long long

#define mem(f, x) memset(f, x, sizeof(f))

#define see(a) cout << #a << " = " << a << endl;

#define xep(i, e) for(int i = 0; i < (e); ++i)

#define rep(i, s, e) for(int i = (s); i <= (e); ++i)

#define drep(i, s, e) for(int i = (s); i >= (e); --i)

#define debug(a, s, e) rep(_i, s, e) cout << endl;

#define debug2(a, s, e, ss, ee) }

const int max = 2e9;

const int min = -2e9;

const int pi = acos(-1.0);

const double eps = 1e-8;

using namespace std;

const int n = 1e5 + 5;

struct h

h(ll n):n(n)

}*h;

int n, p;

ll a[n];

void insert(ll n)

while(p -> next)

p -> next = new h(n);

}bool find(ll n)

p = p -> next;

}return false;

}int main()

int ans = n;

sort(a, a + n);

xep(i, n)}}

printf("%d\n", ans);

}return 0;}/*

1 2 3 4 5 6 7 8

2 4 6 8 10 12 14 16

*/

wikioi1553 互斥的數

時間限制 1 s 空間限制 128000 kb 題目等級 gold 題解 有這樣的乙個集合,集合中的元素個數由給定的n 決定,集合的元素為 n個不同的正整數,一旦集合中的兩個數 x,y滿足 y p x 那麼就認為 x,y這兩個數是互斥的,現在想知道給定的乙個集合的最大子集滿足兩兩之間不互斥。輸入描述...

1553 互斥的數

時間限制 1 s 空間限制 128000 kb 題目等級 gold 題解檢視執行結果 description 有這樣的乙個集合,集合中的元素個數由給定的n決定,集合的元素為n個不同的正整數,一旦集合中的兩個數x,y滿足y p x,那麼就認為x,y這兩個數是互斥的,現在想知道給定的乙個集合的最大子集滿...

CODEVS 1553 互斥的數

有這樣的乙個集合,集合中的元素個數由給定的n決定,集合的元素為n個不同的正整數,一旦集合中的兩個數x,y滿足y p x,那麼就認為x,y這兩個數是互斥的,現在想知道給定的乙個集合的最大子集滿足兩兩之間不互斥。輸入有多組資料,每組第一行給定兩個數n和p 1 n 10 5,1 p 10 9 接下來一行包...