fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. long long a[205];
  5. long long d[2005];
  6. long long kq=0,n;
  7. int s[20005][205];
  8. long long f[205][205];
  9. int dem;
  10. void nhap()
  11. {
  12. ifstream fi("subset.inp");
  13. fi>>n;
  14. for (int i=1;i<=n;i++)
  15. {
  16. fi>>a[i];
  17. d[i]=1;
  18. }
  19. }
  20. void xuly()
  21. {
  22. int danhdau[205];
  23. for (int i=1;i<=n;i++)
  24. {
  25. if (danhdau[i]!=1)
  26. {
  27. kq+=1;
  28. s[kq][0]=1;
  29. s[kq][s[kq][0]]=i;
  30. danhdau[i]=1;
  31. }
  32. for (int j=1;j<=n;j++)
  33. if (a[i]%a[j]==0 || a[j]%a[i]==0)
  34. f[i][j]=1;
  35. else if(danhdau[j]!=1){
  36. int thu;
  37. for (int z=1;z<=s[kq][0];z++)
  38. if (f[z][j]==1)
  39. thu=1;
  40. if (thu!=1){
  41. s[kq][0]+=1;
  42. s[kq][s[kq][0]]=j;
  43. danhdau[j]=1;
  44. }
  45. }else f[i][j]=1;
  46. }
  47. }
  48. void ghi()
  49. {
  50. ofstream fo("subset.out");
  51. fo<<kq<<endl;
  52. for (int i=1;i<=kq;i++)
  53. {
  54. for (int j=1;j<=s[i][0];j++)
  55. fo<<s[i][j]<< " ";
  56. fo<< endl;
  57. }
  58. }
  59. int main()
  60. {
  61. nhap();
  62. xuly();
  63. ghi();
  64. }
  65.  
Success #stdin #stdout 0.01s 5388KB
stdin
Standard input is empty
stdout
Standard output is empty