Advertisement
mercMatvey4

Untitled

Dec 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.92 KB | None | 0 0
  1. //ChuvSU yandex.contest 20!8
  2. //Matvey&Volodya 21-18
  3. //Compiler == GNU c++11 4.9
  4.  
  5. //1
  6.  
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     int n, sum=0;
  14.     cin >> n;
  15.     int a[n];
  16.     for (int i=0;i<n;i++)
  17.         cin >> a[i];
  18.     for (int i=0;i<n;i++)
  19.         sum+=a[i];
  20.     cout<<sum;
  21. }
  22.  
  23. //2
  24.  
  25. #include <iostream>
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30.     int n,temp=0,len=0,m=0,max_len=0;
  31.     cin >> n;
  32.     int a[n];
  33.     for (int i=0; i<n; i++)
  34.         cin >> a[i];
  35.     for (int i=1; i<n; i++)
  36.     {
  37.         if(a[i]<a[i-1])
  38.             len++;
  39.         else{
  40.             if(len>max_len)
  41.             {
  42.                 max_len=len;
  43.                 m=temp;
  44.             }
  45.             len=0;
  46.             temp=i;
  47.             }
  48.     }
  49.     if(max_len>len)
  50.     {
  51.         len=max_len;
  52.         temp=m;
  53.     }
  54.     max_len=0;
  55.     for(int i=temp; i<=temp+len; i++) max_len++;
  56.     cout << max_len;
  57. }
  58.  
  59. //3
  60.  
  61. #include <iostream>
  62. using namespace std;
  63.  
  64. int main()
  65. {
  66.     int n,temp=0,len=0,m=0,max_len=0;
  67.     cin >> n;
  68.     int a[n];
  69.     for (int i=0; i<n; i++)
  70.         cin >> a[i];
  71.     for (int i=1; i<n; i++)
  72.     {
  73.         if(a[i]>a[i-1])
  74.             len++;
  75.         else{
  76.             if(len>max_len)
  77.             {
  78.                 max_len=len;
  79.                 m=temp;
  80.             }
  81.             len=0;
  82.             temp=i;
  83.             }
  84.     }
  85.     if(max_len>len)
  86.     {
  87.         len=max_len;
  88.         temp=m;
  89.     }
  90.     max_len=0;
  91.     for(int i=temp; i<=temp+len; i++) max_len++;
  92.     cout << max_len;
  93. }
  94.  
  95.  
  96. //5
  97.  
  98. #include <iostream>
  99.  
  100. using namespace std;
  101.  
  102. int main()
  103. {
  104.     int N;
  105.     cin >> N;
  106.     int a[N];
  107.     for (int i=0;i<N;i++)
  108.         cin >> a[i];
  109.     for (int i=0;i<N;i++)
  110.         if ((a[i]%2)!=0) cout << a[i] << " ";
  111.     for (int i = 0; i < N; i++)
  112.         if ((a[i]%2)==0) cout << a[i] << " ";
  113.     return 0;
  114. }
  115.  
  116. //6
  117.  
  118. #include <iostream>
  119.  
  120. using namespace std;
  121.  
  122. int main()
  123. {
  124.     int N,i;
  125.     cin >> N;
  126.     int a[N];
  127.     for (int i=0;i<N;i++)
  128.         cin >> a[i];
  129.     for (int i=0;i<N;i++){
  130.         if ((a[i]%2)==0) cout << a[i] << " ";}
  131.     for (int i = 0; i < N; i++){
  132.         if ((a[i]%2)!=0) cout << a[i] << " ";}
  133.     return 0;
  134. }
  135.  
  136.  
  137. //7
  138.  
  139. #include <iostream>
  140.  
  141. using namespace std;
  142.  
  143. int main()
  144. {
  145.     float AvgSum,Sum=0,Count=0;
  146.     int N;
  147.     cin >> N;
  148.     int a[N];
  149.     for (int i = 0; i < N; i++)
  150.         cin >> a[i];
  151.     for (int i = 0; i < N; i++)
  152.     {
  153.         if (a[i]>0)
  154.         {
  155.         Sum+=a[i];
  156.         Count++;
  157.         }
  158.     }
  159.     if (Count==0)
  160.         AvgSum=0;
  161.     else AvgSum=Sum/Count;
  162.     for (int i = 0; i < N; i++)
  163.     {
  164.         if (a[i]<=AvgSum)
  165.             cout << a[i] << " ";
  166.     }
  167. }
  168.  
  169. //8
  170.  
  171. #include <iostream>
  172.  
  173. using namespace std;
  174.  
  175. int main()
  176. {
  177.     int N,Count=0;
  178.     int m;
  179.     cin >> N;
  180.     int a[N];
  181.     for (int i=0;i<N;i++)
  182.         cin >> a[i];
  183.     cin >> m;
  184.     for (int i=0;i<N;i++)
  185.         if (a[i]==m*m) {cout << a[i] << " "; Count++;}
  186.     if (Count==0) cout << "NO";
  187.     return 0;
  188. }
  189.  
  190.  
  191. //9
  192.  
  193. #include <iostream>
  194.  
  195. using namespace std;
  196.  
  197. int main()
  198. {
  199.     int N;
  200.     cin >> N;
  201.     int a[N];
  202.     for (int i = 0; i < N; ++i)
  203.         cin >> a[i];
  204.     for (int i = 0; i < N; ++i)
  205.     {
  206.         if (a[i]!=0) cout << a[i] << " ";
  207.     }
  208.     return 0;
  209. }
  210.  
  211. //10
  212.  
  213. #include <iostream>
  214.  
  215. using namespace std;
  216.  
  217. int main()
  218. {
  219.     int N;
  220.     cin >> N;
  221.     int a[N];
  222.     for (int i = 0; i < N; ++i)
  223.         cin >> a[i];
  224.     for (int i = N; i >= 1; --i)
  225.         for (int j = 0; j < i; ++j)
  226.         {
  227.             if(a[j]==0)
  228.             {
  229.                 int temp = a[j];
  230.                 a[j] = a[j-1];
  231.                 a[j-1] = temp;
  232.             }
  233.         }
  234.     for (int i = 0; i < N; ++i)
  235.         cout << a[i] << " ";
  236.     return 0;
  237. }
  238.  
  239. //11
  240.  
  241. #include <iostream>
  242.  
  243. using namespace std;
  244.  
  245. int main()
  246. {
  247.     int N,K,temp;
  248.     cin >> N;
  249.     long long a[N];
  250.     cin >> K;
  251.     long long b[K];
  252.     for (int i=0;i<N;++i)
  253.         cin >> a[i];
  254.     for (int i=0;i<K;++i)
  255.         cin >> b[i];
  256.     for (int i=0;i<K;++i)
  257.     {
  258.         temp=0;
  259.         for (int j=0;j<N;++j)
  260.         {
  261.             if (b[i]==a[j]) ++temp;
  262.         }
  263.         if (temp==0) cout << "NO ";
  264.             else cout << "YES ";
  265.     }
  266.     return 0;
  267. }
  268.  
  269. //12 (!!!!!!HELLO ITS ME!!!!!!!)
  270.  
  271.  
  272. #include <iostream>
  273.  
  274. using namespace std;
  275.  
  276. void quickSort(unsigned int *numbers, unsigned int left, unsigned int right)
  277. {
  278.     unsigned int pivot;
  279.     unsigned int l_hold = left;
  280.     unsigned int r_hold = right;
  281.     pivot = numbers[left];
  282.     while (left < right)
  283.     {
  284.         while ((numbers[right] >= pivot) && (left < right))
  285.             right--;
  286.         if (left != right)
  287.         {
  288.             numbers[left] = numbers[right];
  289.             left++;
  290.         }
  291.         while ((numbers[left] <= pivot) && (left < right))
  292.             left++;
  293.         if (left != right)
  294.         {
  295.             numbers[right] = numbers[left];
  296.             right--;
  297.         }
  298.     }
  299.     numbers[left] = pivot;
  300.     pivot = left;
  301.     left = l_hold;
  302.     right = r_hold;
  303.     if (left < pivot)
  304.         quickSort(numbers, left, pivot - 1);
  305.     if (right > pivot)
  306.         quickSort(numbers, pivot + 1, right);
  307. }
  308.  
  309. int SearchBinary(unsigned int arr[], unsigned int left, unsigned int right, unsigned int key)
  310. {
  311.     unsigned int midd = 0;
  312.     while (1)
  313.     {
  314.         midd = (left + right) / 2;
  315.         if (key < arr[midd])
  316.         right = midd - 1;
  317.         else if (key > arr[midd])
  318.             left = midd + 1;
  319.                 else
  320.                     return 1;
  321.         if (left > right)
  322.         return 0;
  323.      }
  324. }
  325.  
  326. int main()
  327. {
  328.     unsigned int N,K,MAX,MIN;
  329.     unsigned int a[200000];
  330.     bool n[200000];
  331.     cin>>N;
  332.     cin>>K;
  333.     for ( unsigned int i = 0 ; i < N ; i++)
  334.     {
  335.         cin>>a[i];
  336.     }
  337.     quickSort(a,0,N-1);
  338.     MIN = a[0];
  339.     MAX = a[N-1];
  340.     for ( unsigned int i = 0 ; i < K ; i++)
  341.     {
  342.         unsigned int b;
  343.         cin>>b;
  344.         n[i] = false;
  345.         if ((b<MIN)||(b>MAX)) continue;
  346.         n[i] = SearchBinary(a,0,N-1,b);
  347.     }
  348.     for ( unsigned int i = 0 ; i < K ; i++)
  349.     {
  350.         if (n[i]) cout<<"YES ";
  351.         else cout<<"NO ";
  352.     }
  353.     return 0;
  354. }
  355.  
  356. //13
  357.  
  358.  
  359. #include <iostream>
  360.  
  361. using namespace std;
  362.  
  363. int main()
  364. {
  365.     int n,val=1;
  366.     cin >> n;
  367.     int a[n],d[n];
  368.     for (int i = 0; i < n; i++)
  369.         cin >> a[i];
  370.     d[0] = a[0];
  371.     for (int i = 0; i < n; i++)
  372.     {
  373.         bool r=true;
  374.         for (int j = 0; j < val; j++)
  375.             if (a[i]==d[j]) {r=false; break;}
  376.         if (r) {d[val] = a[i]; val++;}
  377.     }
  378.     for (int i = 0; i < val; i++)
  379.     cout << d[i] << " ";
  380.     return 0;
  381. }
  382.  
  383.  
  384. //15
  385.  
  386. #include <iostream>
  387.  
  388. using namespace std;
  389.  
  390. int main()
  391. {
  392.     int N,temp=0;
  393.     cin >> N;
  394.     int arr[N][N];
  395.     for (int i=0;i<N;i++)
  396.     {
  397.         for (int j=0;j<N;j++)
  398.         {
  399.             if(i==j)
  400.             {
  401.                 arr[i][j]=0;
  402.                 for (int k=0;k<N-i;k++)
  403.                 {
  404.                     arr[i+k][j]=k;
  405.                 }
  406.                 for (int k=i;k>=0;k--)
  407.                 {
  408.                     arr[k][j]=temp;
  409.                     temp++;
  410.                 }
  411.                 temp=0;
  412.             }
  413.         }
  414.     }
  415.     for (int i=0;i<N;i++){
  416.     for (int j=0;j<N;j++){
  417.         cout << arr[i][j] << " ";}
  418.         cout << endl;}
  419. }
  420.  
  421.  
  422. //16
  423.  
  424.  
  425. #include <iostream>
  426.  
  427. using namespace std;
  428.  
  429. int main()
  430. {
  431.  int N;
  432.  cin>>N;
  433.  int a[N];
  434.  for (int i=0;i<N;i++)  
  435.     cin>>a[i];  
  436.  for (int i=0;i<N;i++)
  437.     if (a[i]!=0) cout << a[i] << " ";
  438.  for (int i=0;i<N;i++)
  439.     if (a[i]==0) cout << a[i] << " ";
  440.  return 0;
  441. }
  442.  
  443.  
  444. //Qotlets ))))))))) (na samom dele grustno)
  445.  
  446. #include <iostream>
  447. using namespace std;
  448.  
  449. int main()
  450. {int k, m,n, min;
  451.  cin>>k>>m>>n;
  452. if (n<=k) {min=2*m; cout<<min;}
  453.    else if (n*2%k==0) {min=m*(n*2/k); cout<<min;}
  454.              else {min=m*(1+(n*2/k)); cout<<min;};
  455.     return 0;
  456. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement