模擬8 03 分組

2022-05-06 22:48:08 字數 2517 閱讀 8215

好題

k=1做法:

直接倒著找,滿足貪心性質,預處理出每個平方數就行.....

1 #include2 #include3 #include

4 #include5 #include6 #include7 #include8 #include

9 #include10

#define maxn 300001

11#define int long long

12#define ps push_back

13using

namespace

std;

14int

a[maxn];

15int

n,k,kuan;

16bool

biao[maxn];

17int

ans[maxn];

18int

poww[maxn];

19void

work1()

2035 end--;36}

37else

3845 end--;46}

47}48 printf("

%lld\n

",ans[0]+1

);49

if(ans[0]==0)printf("\n"

);50

for(int i=ans[0];i>=1;--i)

5154 cout<

56signed main()

5767 kuan=maxn+maxn;

68for(int i=2;i<=sqrt(kuan)+1;++i)

6972

if(k==1

)work1();

73else printf("

1\n\n");

74}

75/*

765 1

771 3 15 10 6

7879

*/

k==1做法

k=2做法:

其實這個我沒打出正解並查集

用二分圖強行卡常a了,把每個敵人和自己連邊,染色判斷

1 #include2 #include3 #include4 #include

5 #include6 #include7 #include8 #include9 #include

10 #include11

#define maxn 1000001

12#define ps push_back

13using

namespace

std;

14int

a[maxn];

15 vectorv[650001

];16

int n,k;bool

tong[maxn];

17bool

biao[maxn];

18int

ans[maxn];

19int

poww[maxn];

20int

last[maxn];

21void

work1()

2236

}37 last[a[i]]++;38}

39 printf("

%d\n

",ans[0]+1

);40

for(int i=ans[0];i>=1;i--)

41 printf("

%d "

,ans[i]);

42 cout<

44int

col[maxn];

45bool dfs(int x,int color,int r,int l,int

fa)46

57if(col[to]==col[x])

5861}62

return1;

63}64signed main()

65

71for(int i=1;i<=522;++i)

7276

if(k==1

)work1();

77else

7888}89

if(!dfs(end,1,tail,end,0

))90

96for(int i=tail;i>=end;i--)

97100

}101 printf("

%d\n

",ans[0]+1

);102

if(ans[0]==0)cout<

103for(int i=ans[0];i>=1;--i)

104

107}

108 }

view code

2066 分組統計

時間限制 1 sec 記憶體限制 32 mb 提交 474 解決 115 提交 狀態 討論版 命題人 外部匯入 先輸入一組數,然後輸入其分組,按照分組統計出現次數並輸出,參見樣例。輸入第一行表示樣例數m,對於每個樣例,第一行為數的個數n,接下來兩行分別有n個數,第一行有n個數,第二行的n個數分別對應...

4 分組聚合

引數名 接受 含義 預設 by 1.若為函式,則對索引進行計算並分組 2.若為字典 series,則將字典 series的值做為分組依據 3.若為numpy陣列,則以陣列元素為分組依據 4.若為字串 字串列表,則以其所代表的字段進行分組 無axis int表示操作軸向 0level int 索引名 ...

演算法期中1000 分組

description 對於乙個整數數列a 0 a 1 a n 1 進行分組,要求每組1到2個數,並且同組之和不能大於w.求最少可以分成多少組.1 n 100000,1 a i w 1000000000.請實現下面solution類中計算minpartition a,w 的函式.class solu...