Common Board#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAX = 1e5+10; const ll ZERO = 0; #define endl '\n' #define dokme(x) cout << x ; return(0); #define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); stack < char > stk; int main(){ migmig; stk.push('.'); char c[200001]; cin >> c; int n=strlen(c); for (int i =0; i < n ; i ++ ){ if (stk.top()!=c[i]){ stk.push(c[i]); } else{ stk.pop(); } } n=stk.size()-1; memset(c,0,sizeof(c)); for (int i = 0 ; i<n ; i ++ ){ c[n-i-1]=stk.top(); stk.pop(); } cout << c; } Im struggling with it for few days, but absolutely have no idea how to do it! Any hints?? What specifically are you having a problem with? For example, are you trying to figure out how to write your code so that it reads and saves the input? import java.util.Scanner; public class Main { private static void checking(double a){ if(Math.sqrt(a)%1==0){ System.out.printf("%.0f",Math.sqrt(a)); }else{ System.out.printf("%.4f",Math.sqrt(a)); } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Сколько чисел хотите ввести: "); int a = scanner.nextInt(); double[] b = new double[a]; for (int i = 0; i < b.length; i++) { System.out.print("Число " + (i+1) + ": "); b[i] = scanner.nextDouble(); } for(double c : b){ System.out.print("Корень " + c + " = "); checking(c); System.out.println(); } } } I'm not sure what's causing the runtime error, but I tried your code on an online compiler and this was the error message I got: Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextDouble(Scanner.java:2564) at Main.main(Main.java:22) import math import re input_string = '' while True: line = input() if line: input_string = input_string + ' ' + line else: break input_digits = [int(x) for x in input_string.replace('\n',' ').replace('\t', ' ').split()] input_digits = input_digits[::-1] for int in input_digits: sqr_root = math.sqrt(int) print(format(sqr_root, '.4f')) #Thanks for the help guys! I tested your code on some online compilers, and the last two answers were printed, but not the first two. It looks like your algorithm correctly read the first line, but because there were empty lines for the next couple lines, your break statement kept the code from reading the last two lines in the example testcase. You need to change the code so it can read all the lines, even the ones that come after empty lines. 2^19 or another where factorized number = 19 IF you have TL, try this test: 18 aasda0sd basdasdasd casdasd asdasd33a 0b12asdasd ca45sdasd cdasdas3das dasd0asda2ds e1dasqew sdsdad4asdsaf dasda0sdasd 0gasdasd asdasda5sa asdasdasd3b asda0sdasdc aqwewq6e bqweqwe cqweq0we cqweqw7e dqweqwe eqw3ewqees fsadasd8asd dasdasdas0d gasdasd asdasds9adasa abasdas3dads casdasd12 qweqwew123qea bqweqw3ewqe cweqqwee csadas12d dasdas0d ed0dsdadsa fdasdasd33 dasdasds30ad gasasdsad adasdasd123d badas3ddasda cdasds0adas asdads455as basdasda2sd casdasdd0sa cqwewq123e deeqw12e eqw1easda8d fasd123asd dasdasds3a1dqw gqwe9wqewes jeqweqw123e eqweq123wewee hwewe9wqq ldszczx123c ad123sdasdaq qweweq09f ans: 18 Edited by author 10.08.2019 22:28 Edited by author 10.08.2019 22:28 Edited by author 10.08.2019 22:28 #include<bits/stdc++.h> using namespace std; int main() { double a,b,c,d,m,n,l,p,t,s,k; cin>>a>>b>>c>>d>>m>>n>>l; p=sqrt((a-m)*(a-m)+(b-n)*(b-n)); t=sqrt((c-m)*(c-m)+(d-n)*(d-n)); s=max(p,t); if(s>l){s-=l; } else{ s=0;} k=min(p,t); if(k<=l){ k=0; } else if(p==t){ a=(a+c)/2,b=(b+d)/2; k=sqrt((a-m)*(a-m)+(b-n)*(b-n)); if(k<=l){ k=0; } else{ k-=l; } } else{ while(abs(p-t)>.001){ if(p<t){ c=(a+c)/2,d=(b+d)/2; t=sqrt((c-m)*(c-m)+(d-n)*(d-n)); } else{ a=(a+c)/2,b=(b+d)/2; p=sqrt((a-m)*(a-m)+(b-n)*(b-n)); } } k=min(p,t); if(k<=l){ k=0; } else{ k-=l; } } cout<<fixed<<setprecision(2)<<k<<endl; cout<<fixed<<setprecision(2)<<s<<endl; } There seems to be some junk at the end of test 27. My solution with "while (read()) solve();" got WA but when I removed it I got OK. Test was fixed. Thank you! Методы Программирования и Прикладные Алгоритмы My solution is O(n) (<=60 * n iterations) but I have TL on python Help me to read fast data input My input code: n, l, r = map(int, input().split()) tokens = sys.stdin.read().split() a = list(map(int, tokens)) Thx But I solved problem using C++. The same algo but new implementation (added if ((prod / (double)1000000000) * a[j-1]> 1000000000) j = 0; else prod *= a[j-1];) Edited by author 07.08.2019 13:55 I used some methods, got TLE || WA ...T T ... You can enumerate P . Think carefully and you will get a O(sqrt(n)) solution. Spend some time for enum, cause i don't wanna to calculate in float variables. So fun!) #include<bits/stdc++.h> using namespace std; int main(){ unsigned long long int n; try{ cin >> n; cout << n%7 << endl; }catch(exception e){ cout << 1 << endl; } return 0; } Some have claimed that this is a very difficult problem. Not true! There is a reasonably simple and very fast DP-solution to this problem. No string algorithms are required beyond the naive ones that every non-programmer knows. Hint: Store the solution for sentences of length k in A[k], and store the number of strings that end with some forbidden word i (0 < i < P), but does not contain any other forbidden words as substrings in F[i][k]. Then construct the solution from A[k] to A[k+1], updating F[i][k+1] as well for each i. For each new character that you tuck onto the end of a valid string of length k, you get A[k] more valid strings, except those that end with a forbidden word, so those strings need to be removed. But make sure you don't remove stuff that you've assumed that you already removed earlier in the string - that's where F[i][k] comes in handy. every body handshakes all else his couple so n*(n-1) div 2 - k (couples doesnt handshake eachother)! --> Var n,k:integer; begin readln(n,k); writeln(((n*(n-1)) div 2) -k); end. Aidin_n7 What is The Autor Thinking? What's the meaning of the spliting group numbers? It just piss me off. Yep, this is the one way for solution. I've met problem like that earlier. Statements consist kinda "you need to get very-very much operation with binary code of number", but after some tests we understood, that solution was kinda "ans = n*(-1)". And it's good to have a short cut in problems for clever men;) This is my solution O(M log N) #include <bits/stdc++.h> #define in(x) freopen(x,"r",stdin) #define out(x) freopen(x,"w",stdout) #define N 100500 #define oo ll(1e16) #define P pair < int, int > #define PP pair < pair < int, int >, int > #define F first #define S second #define pb push_back #define el endl #define base ll(1e9 + 7) using namespace std; typedef long long ll; typedef long double ld; int n, m, y; bool o; int bin(int x, int st) { int res = 1; for(; st > 0;) { if (st & 1) res = (res * x) % m; x = (x * x) % m; st >>= 1; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> y; o = 0; for (int i = 1; i < m; i++) { int cur = bin(i, n); if (cur == y) cout << i << ' ', o = 1; } if (!o) cout << -1; } Test: 123131 Answer: 123321 Thanks! Didn't make numbers equal to zero in encreasing numbers after the right one of comparing; Use scanline y = -x + a We need to use no more than 6 points If you want to be fast use k-statistic in O(n) For better explanation write here: myironmistake@gmail.com Edited by author 06.08.2019 18:42 Even though it took me almost 2 hours to solve I'm surprised this has difficulty of 1539. It doesn't require any special knowledge and almost anyone can solve this. Solution is pretty straightforward. Anyone can give me this test case? DELETED Edited by author 04.08.2019 22:55 |
|