Advertisement
MasFlam

piwo reszta

Dec 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. // ozd
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n, k;
  9. cin>>n;
  10. cin>>k;
  11.  
  12. int neededRed = n*2;
  13. int neededGreen = n*5;
  14. int neededBlue = n*8;
  15.  
  16. int booksToBuy = 0;
  17. booksToBuy += ceil(double(neededRed)/k);
  18. booksToBuy += ceil(double(neededGreen)/k);
  19. booksToBuy += ceil(double(neededBlue)/k);
  20.  
  21. cout << booksToBuy << endl;
  22.  
  23. return 0;
  24. }
  25. //////////////////////////// ppk
  26. #include <bits/stdc++.h>
  27.  
  28. using namespace std;
  29.  
  30. long long getCSquared(int a , int b){
  31. return pow(a, 2) + pow(b, 2);
  32. }
  33.  
  34. int main()
  35. {
  36. int n;
  37. cin>>n;
  38. int x[100000];
  39. int y[100000];
  40. for(int i = 0; i < n; i++){
  41. cin>>x[i];
  42. cin>>y[i];
  43. }
  44.  
  45. int maxX = 0;
  46. int maxY = 0;
  47.  
  48. for(int i = 0; i < n; i++){
  49. if(getCSquared(x[i], y[i]) > getCSquared(maxX, maxY)){
  50. maxX = x[i];
  51. maxY = y[i];
  52. }
  53. }
  54.  
  55. while(maxY > 0){
  56. maxX++;
  57. maxY--;
  58. }
  59.  
  60. cout << maxX << endl;
  61.  
  62. return 0;
  63. }
  64. ////////////////////// raz
  65. #include <bits/stdc++.h>
  66.  
  67. using namespace std;
  68.  
  69. string reverseString(string word){
  70. string output = "";
  71.  
  72. for(int i = word.length()-1; i >= 0; i--){
  73. output = output + string(1, word[i]);
  74. }
  75.  
  76. return output;
  77. }
  78.  
  79. string scramble(string word){
  80. string output = "";
  81. string wordReverse = reverseString(word);
  82.  
  83. for(int i = 0; i < floor(word.length()/2.0); i++){
  84. output = output + string(1, word[i]) + string(1, wordReverse[i]);
  85. }
  86.  
  87. if(word.length() % 2 == 1){
  88. output = output + word[ceil(word.length()/2.0 - 1)];
  89. }
  90.  
  91. return output;
  92. }
  93.  
  94. int main()
  95. {
  96. int n;
  97. cin>>n;
  98. string words[1000];
  99. for(int i = 0; i < n; i++){
  100. cin>>words[i];
  101. }
  102.  
  103. for(int i = 0; i < n; i++){
  104. cout << scramble(words[i]) << endl;
  105. }
  106.  
  107. return 0;
  108. }
  109. ////////////////// wla
  110. #include <bits/stdc++.h>
  111.  
  112. using namespace std;
  113.  
  114. int main()
  115. {
  116. int n;
  117. cin>>n;
  118. vector<int> a;
  119. for(int i = 0; i < n; i++){
  120. int val;
  121. cin>>val;
  122. a.push_back(val);
  123. }
  124. sort(a.begin(), a.end());
  125.  
  126. int stolen = 0;
  127.  
  128. int prevLeftIndex = 0;
  129. for(int i = 1; i < n; i++){
  130. if(a[prevLeftIndex] == a[i] - 1)
  131. prevLeftIndex++;
  132. else {
  133. stolen += a[i] - a[prevLeftIndex] - 1;
  134. prevLeftIndex++;
  135. }
  136. }
  137.  
  138. cout << stolen << endl;
  139.  
  140. return 0;
  141. }
  142. ////////////// wyd
  143. #include <bits/stdc++.h>
  144.  
  145. using namespace std;
  146.  
  147. int main()
  148. {
  149. int n;
  150. cin>>n;
  151. int r;
  152. cin>>r;
  153.  
  154. int minCoins = r/n + (r%n != 0);
  155.  
  156. cout << minCoins << endl;
  157.  
  158. return 0;
  159. }
  160. /////////////////////// bin
  161. #include <bits/stdc++.h>
  162.  
  163. using namespace std;
  164.  
  165. int howManyZeros(string s){
  166. int out = 0;
  167. for(int i = 0; i < s.length(); i++){
  168. if(s[i] == '0') out++;
  169. }
  170. return out;
  171. }
  172.  
  173. string modify(string val){
  174. string output = "";
  175.  
  176. if(val == "0")
  177. output = "0";
  178. else {
  179. output = "1";
  180. for(int i = 0; i < howManyZeros(val); i++) output = output + "0";
  181. }
  182.  
  183. return output;
  184. }
  185.  
  186. int main()
  187. {
  188. int n;
  189. cin>>n;
  190. for(int i = 0; i < n; i++){
  191. string b;
  192. cin>>b;
  193. cout << modify(b) << endl;
  194. }
  195. return 0;
  196. }
  197. //////////////////// fig
  198. #include <bits/stdc++.h>
  199.  
  200. using namespace std;
  201.  
  202. int main()
  203. {
  204. int n;
  205. cin>>n;
  206. vector<int> shapes;
  207. for(int i = 0; i < n; i++){
  208. int s;
  209. cin>>s;
  210. shapes.push_back(s);
  211. }
  212.  
  213. bool canFind = false;
  214.  
  215. for(int i = 1; i < n-1; i++){
  216. if(shapes[i] == 0){
  217. if((shapes[i-1] == 1 && shapes[i+1] == 2) || (shapes[i-1] == 2 && shapes[i+1] == 1)){
  218. canFind = true;
  219. break;
  220. }
  221. }
  222.  
  223. if(shapes[i] == 1){
  224. if((shapes[i-1] == 0 && shapes[i+1] == 2) || (shapes[i-1] == 2 && shapes[i+1] == 0)){
  225. canFind = true;
  226. break;
  227. }
  228. }
  229.  
  230. if(shapes[i] == 2){
  231. if((shapes[i-1] == 0 && shapes[i+1] == 1) || (shapes[i-1] == 1 && shapes[i+1] == 0)){
  232. canFind = true;
  233. break;
  234. }
  235. }
  236. }
  237.  
  238. if(canFind)
  239. cout << "TAK" << endl;
  240. else
  241. cout << "NIE" << endl;
  242.  
  243. return 0;
  244. }
  245. //////////////////// pla
  246. #include <bits/stdc++.h>
  247.  
  248. using namespace std;
  249.  
  250. int main()
  251. {
  252. int n;
  253. cin>>n;
  254. vector<int> a;
  255. for(int i = 0; i < n; i++){
  256. int v;
  257. cin>>v;
  258. a.push_back(v);
  259. }
  260.  
  261. while(true){
  262. if(a.size() > 0){
  263. if(a[0] == 0) a.erase(a.begin());
  264. else break;
  265. } else break;
  266. }
  267.  
  268. if(a.size() > 0){
  269. bool zeros = false;
  270. int zerosStartIndex;
  271. for(int i = 0; i < a.size(); i++){
  272. if(!zeros && a[i] == 0){
  273. zeros = true;
  274. zerosStartIndex = i;
  275. }
  276.  
  277. if(zeros && a[i] != 0){
  278. if(i - zerosStartIndex >= 2){
  279. a.erase(a.begin()+zerosStartIndex, a.begin()+i);
  280. i = zerosStartIndex;
  281. zeros = false;
  282. } else {
  283. zeros = false;
  284. }
  285. }
  286. }
  287. }
  288.  
  289. while(true){
  290. if(a.size() > 0){
  291. if(a[a.size()-1] == 0) a.erase(a.end()-1);
  292. else break;
  293. } else break;
  294. }
  295.  
  296. cout << a.size() << endl;
  297.  
  298. return 0;
  299. }
  300. ///////////////// dzi
  301. #include <bits/stdc++.h>
  302. #include <chrono>
  303.  
  304. using namespace std;
  305.  
  306. int powersOf2[30] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912};
  307.  
  308. bool isPowerOf2(int n){
  309. for(int i = 0; i < 30; i++){
  310. if(n == powersOf2[i]) return true;
  311. }
  312. return false;
  313. }
  314.  
  315. long long strangeSum(long long n){
  316. long long sum = (n+1) * n/2;
  317.  
  318. for(int i = 0; i < 30; i++){
  319. if(n >= powersOf2[i]) sum -= 2*powersOf2[i];
  320. }
  321.  
  322. return sum;
  323. }
  324.  
  325. int main()
  326. {
  327. int z;
  328. cin>>z;
  329.  
  330. for(int i = 0; i < z; i++){
  331. int n;
  332. cin>>n;
  333. cout<<strangeSum(n)<<endl;
  334. }
  335. return 0;
  336. }
  337. /////////////// sch
  338. #include <bits/stdc++.h>
  339.  
  340. using namespace std;
  341.  
  342. int main()
  343. {
  344. int n;
  345. cin>>n;
  346. int a[10000];
  347. for(int i = 0; i < n; i++){
  348. cin>>a[i];
  349. }
  350.  
  351. queue<int> stairs;
  352. int stairCounter = 1;
  353. for(int i = 1; i <= n; i++){
  354. if(i!=n){
  355. if(a[i] <= a[i-1]){
  356. stairs.push(stairCounter);
  357. stairCounter = 1;
  358. } else stairCounter++;
  359. } else stairs.push(stairCounter);
  360. }
  361.  
  362. cout<<stairs.size()<<endl;
  363. while(!stairs.empty()){
  364. cout<<stairs.front()<<" ";
  365. stairs.pop();
  366. }
  367.  
  368. return 0;
  369. }
  370. ////////////////////// tpa
  371. #include <bits/stdc++.h>
  372.  
  373. using namespace std;
  374.  
  375. bool palindromePossible(int arr[], int n){
  376. for(int i = 0; i <= n/2; i++){
  377. if((arr[i]==1 && arr[n-1-i]==2) || (arr[i]==2 && arr[n-1-i]==1))
  378. return false;
  379. }
  380. return true;
  381. }
  382.  
  383. int main()
  384. {
  385. int n;
  386. cin>>n;
  387. int a, b;
  388. cin>>a;
  389. cin>>b;
  390. int dancers[1000];
  391. for(int i = 0; i < n; i++){
  392. cin>>dancers[i];
  393. }
  394.  
  395. if(palindromePossible(dancers, n)){
  396. int cost = 0;
  397.  
  398. for(int i = 0; i < floor(n/2.0); i++){
  399. if(dancers[i]==1 && dancers[n-1-i]==0)
  400. cost += a;
  401. else if(dancers[i]==0 && dancers[n-1-i]==1)
  402. cost += a;
  403. else if(dancers[i]==2 && dancers[n-1-i]==0)
  404. cost += b;
  405. else if(dancers[i]==0 && dancers[n-1-i]==2)
  406. cost += b;
  407. else if(dancers[i]==0 && dancers[n-1-i]==0)
  408. cost += min(a, b);
  409. }
  410. if(n%2 == 1){
  411. if(dancers[(int) floor(n/2.0)] == 0) cost += min(a, b);
  412. }
  413.  
  414. cout<<cost<<endl;
  415.  
  416. } else cout<<"NIE"<<endl;
  417.  
  418. return 0;
  419. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement