Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | C++ sliding window, queue | babaka | 1910. Руины титанов: сокрытый вход | 8 фев 2017 11:46 | 1 | #include <iostream> #include <queue> using namespace std; int calculate (queue<int> wind) { int result = 0; for (int i = 0; i < 3; i++) { result += wind.front(); wind.pop(); } return result; } int main() { int n, sum = 0, max=0, el, position=2, middle=2; queue<int> window; cin >> n; for (int i = 0; i < 3; i++) { cin >> el; window.push(el); max += el; } for (int i = 0; i < n-3; i++) { cin >> el; window.push(el); window.pop(); sum = calculate(window); position++; if(sum > max) { max = sum; middle = position; } } cout << max << " " << middle; return 0; } | | wa9. | Andrew | 1068. Сумма | 6 фев 2017 17:28 | 2 | wa9. Andrew 27 ноя 2016 17:21 import java.util.*; public class JavaApp { public static void main(String[] args) { int i=0; Scanner scan = new Scanner(System.in); int n=scan.nextInt();
if ((n>=1)&&(n<10000)){ i=n *(n + 1) / 2; System.out.print(i);} else if ((n<=1)&&(n>-10000)){ i=-((-n) *(1 -n) / 2) + 1; System.out.print(i);} }; } import java.util.Scanner; public class tests {
public static void main(String[] args) { int i=0; Scanner scan = new Scanner(System.in); try{ int n=scan.nextInt(); if ((n>=1)&&(n<=10000)){ i=n *(n + 1) / 2; System.out.print(i);} else if ((n<=1)&&(n>=-10000)){ i=-((-n) *(1 -n) / 2) + 1; System.out.print(i);} } finally { scan.close(); } } } | | What is 33 Test? | ProeBos | 1854. Переговоры с Парфией | 6 фев 2017 05:24 | 7 | try this: 45000270000405 answer: 9000054000081 or this: 907500003300000003 answer: 302500001100000001 Edited by author 10.10.2011 10:41 907500003300000003 right is 1 To clarify: IFullMetalLeon is not telling the truth; the correct answer to 907500003300000003 is 302500001100000001. and you could try 100102036020202601, the answer is 10010202601 I'm stuck on test 33. Please, explain, is 9000054000081 really correct answer? 9000054000081 = 3^2 + 100000600009^1. It obviously has even divisors: (2+1) * (1+1) = 6. They are 1, 3, 9, 100000600009, 300001800027, 900005400081. And 302500001100000001 is prime, thus it has 2 divisors (1 and self). Where am I wrong? 302500001100000001=550000001^2 And is has 3 uneven divisors: 1, 550000001, 302500001100000001. And every X=Y^2 has uneven number of uneven divisors. Edited by author 31.05.2012 18:57 | | This is the right solution | netman | 1110. Степень | 6 фев 2017 02:07 | 3 | This is the right solution Sorry for my english var ans: array[1..1000] of longint; n,m,y,q,i: longint; function BinPow(x,y: longint): longint; begin if y=1 then BinPow:=x else if y mod 2=0 then BinPow:=sqr(BinPow(x,y div 2)) mod M else BinPow:=(sqr(BinPow(x,y div 2))*x) mod M; end; begin readln(n,m,y); q:=0; for i:=0 to m-1 do begin if BinPow(i,n)=y then begin inc(q); ans[q]:=i; end; end; for i:=1 to q do write(ans[i],' '); if q=0 then writeln(-1); end. My solve in C++: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std; __int64 n,m,y;
int binpow(int a, int n){ if (n == 0) return 1; if (n % 2 == 1) return (binpow (a, n-1)*a)%m; else{ int b = (binpow(a, n/2)); return (b*b)%m; } }
bool ok; main(){ scanf("%I64d%I64d%I64d",&n,&m,&y); for(int i=0; i < m; i++){ if(binpow(i,n)%m==y){ cout<<i<<" "; ok=1; } } if(!ok) return cout<<"-1",0;
return 0; } What it is? else if y mod 2=0 then BinPow:=sqr(BinPow(x,y div 2)) mod M else BinPow:=(sqr(BinPow(x,y div 2))*x) mod M; | | Why WA#1?? Help me, please!! | quangduytr | 1226. йынтарбО кодяроп | 5 фев 2017 21:40 | 5 | #include <bits/stdc++.h> using namespace std; string a,b; string re(long long c, long long d,string x){ string y=""; for(long long i=d; i>=c; i--) y=y+x[i]; return y; } string re2(string x){ long long t=0; string res=""; for(long long i=0; i<x.size(); i++){ int q=(int)x[i]; if(q<65||(q>90&&q<97)||q>122){ res=res+re(t,i-1,x); res=res+x[i]; t=i+1; } } res=res+re(t,x.size()-1,x); return res; } int main() { while(getline(cin,a)){ istringstream iss; iss.clear(); iss.str(a); while(iss>>b) cout<<re2(b)<<" "; cout<<endl; } } In the end you write empty line. You must delete your last cout. Thanks you. But I repaired and still WA#1 Try next tests(be attentive to the newline and whitespace): 1) asdad asd sf dv answer: dadsa dsa fs vd 2)1 2 3 $ asd#!@#sad%$#%2 sdSA d!23!`123?<M@! ^^&(&*^&as asf kljdka jd1892u31ASDASD11 end. answer: 1 2 3 $ dsa#!@#das%$#%2 ASds d!23!`123?<M@! ^^&(&*^&sa fsa akdjlk dj1892u31DSADSA11 dne. 3)You must inverse word and all. But y ou could forget about the spaces and line breaks ! answer: uoY tsum esrevni drow dna lla. tuB y uo dluoc tegrof tuoba eht secaps dna enil skaerb ! Oh, I failed in test 1 and then got AC. Tks u so much ^^ Edited by author 05.02.2017 21:40 | | About Statement | Felix_Mate | 1822. Война Уго II | 5 фев 2017 21:09 | 1 | "King Hugo II wants to state the number x in his recruitment order. The king needs as many soldiers as possible for his military campaign. However, if the recruitment takes more than t days, the enemy may learn about the imminent intrusion and strike first. Help Hugo II find the maximal possible value of x." We must find "maximal possible value of x" with "if the recruitment takes more than t days, the enemy may learn about the imminent intrusion and strike first" without "The king needs as many soldiers as possible for his military campaign"!!! | | wa24 help | Grandmaster | 1635. Мнемоника и палиндромы | 5 фев 2017 04:22 | 1 | nvm accepted Edited by author 05.02.2017 04:33 | | Help! I can't find error | Felix_Mate | 1995. Запрещённые специи | 4 фев 2017 23:36 | 1 | My code: const nmax=111111; var a:array[1..nmax] of int64; n,k,p:longint; i,cnt,cntmax,max:longint; sum:int64; BEGIN readln(n,k); read(p);
for i:=1 to n-k do a[i]:=1; sum:=n-k; cnt:=n-k; cntmax:=1; max:=2;
for i:=n-k+1 to n do begin if(100*cnt<p*(i-1)) then begin inc(max); inc(cnt,cntmax-1); cntmax:=1; end else inc(cntmax);
a[i]:=max; inc(sum,max); end;
writeln(sum); for i:=1 to n do write(a[i],' '); END.
| | problem 1086 | Ajana | 1086. Криптография | 4 фев 2017 15:59 | 2 | #include<stdio.h> int main() { int n,i,j,c,t,T; scanf("%d",&T); while(T--) { scanf("%d",&n); for(j=2;;j++) { c=0; t=0; for(i=2;i<=j/2;i++) { if(j%i==0) { c++; break; } } if(c==0) t++; if(t==n) { printf("%d\n",j); break; } } } return 0; } why TLE?? Edited by author 04.02.2017 11:04 Edited by author 04.02.2017 11:05 Edited by author 04.02.2017 11:08 Error here: t=0. You wanted this: #include<stdio.h> int main() { int n,i,j,c,t,T; scanf("%d",&T); while(T--) { scanf("%d",&n); t=0; for(j=2;;j++) { c=0; for(i=2;i<=j/2;i++) { if(j%i==0) { c++; break; } } if(c==0) t++; if(t==n) { printf("%d\n",j); break; } } } return 0; } But your algo will get TL on test: 15000 15000 .... 15000 (15001 times) | | WA 9 Java | keekkenen | 1002. Телефонные номера | 3 фев 2017 23:57 | 1 | Please, help some critical test case ps. I fix it ) Edited by author 04.02.2017 18:08 | | WA 14 ???? Help | Ostap Korkuna | 1420. Целочисленное комплексное деление | 3 фев 2017 23:50 | 4 | I can't understand what is wrong? Maby something with calculations and rounding??? Can anyone help me? Thanks [code deleted] Edited by moderator 22.02.2006 00:48 correst your x and y to: [code deleted] Edited by author 21.11.2005 04:45 Edited by moderator 22.02.2006 00:49 Can you tell me how to solve this problem?? Утверждение: задача эквивалентна следующей: нужно найти все комплексные q с целыми коэффициентами, удовлетворяющие |a-bq|<|b|. Если |b|=0, то решений нет Иначе |b|>0. Тогда условие эквивалентно |a/b - z|<1. Пусть a=a1+b1i, b=a2+b2i, q=q1+q2i. Тогда получим |alfa/gamma-q1+i(beta/gamma+q2)|<1 <=> ((alfa-gamma*q1)/gamma)^2+((beta+gamma*q2)/gamma)^2<1, где gamma=a2*a2+b2*b2, alfa=(a1*a2+b1*b2)/gamma, beta=i(a2*b1-a1*b2)/gamma. Теперь просто можно пройтись по всем q1 и q2 (они меняются от -1+alfa/gamma до 1+alfa/gamma и от -1-beta/gamma до 1-beta/gamma) и проверить условие. | | I got AC, but my algorythm is standart( O(m*2^n) ). How solve faster? (i need in idea) | Felix_Mate | 1326. Крышки | 3 фев 2017 21:08 | 3 | Hi. I've also got AC with O(m*2^n), but it seems that it's a bit more fast. Here's an idea. Each set of taps or a combination of sets has corresponding bit mask. We have an array int minPrice[2^N]. Obviously, index is a mask, element — min price for buying such combination of taps. Initially the only !=0 elements are those each corresponding to one of predefined M sets. Then the DP comes. We go from 0-th element to the last (11...1 target). If i-th element !=0, we process it: a) if i corresponds to one of M predefined sets, we try to OR "i" with all younger mask with !=0 price. b) if i doesn't correspond to any predefined set, thus, it's a combination of some predefined sets, then we OR this "i" with younger predefined masks ONLY (not all younger "j" !=0). However, there's still a question to those guys who got AC in less than 0.1 second. Especially to those who did it in ~200 KB. | | No subject | Felix_Mate | 1228. Массив | 1 фев 2017 17:12 | 1 | Edited by author 01.02.2017 17:12 | | WA Test#3 | vndd | 1563. Баяны | 1 фев 2017 05:33 | 1 | Edited by author 16.02.2017 22:39 | | Unclear problem statement in russian | Sirko | 1326. Крышки | 31 янв 2017 15:21 | 1 | "В первой строке записано число N — количество недостающих Петрову крышек (1 ≤ N ≤ 20)." vs "В последней строке перечислен минимальный набор крышек, который Петров намерен купить в любом случае." | | Голд место это только первое? или первые н мест? | Mescheryakov_Kirill [SESC17] | 1868. Конкурс прогнозов | 30 янв 2017 22:59 | 2 | | | test for WA#8 | hoan | 1183. Brackets Sequence | 29 янв 2017 06:37 | 7 | input: ))(())(( output: ()()(())()() i hope it can help you. sorry for my poor english. GOOD LUCK!!! Hi, The output of my application for your test is the same. But the judge tell me WA#8 :S. try this input : [][] output : [][] hello,I get the same output as you said but yet i get WA#8.Any suggestions?! Try this (][)) .... answer should be ([][])() or (([][])) Thanks, man, that helped me :) | | WA#3 | Rinotto | 1297. Палиндромы | 27 янв 2017 22:12 | 1 | WA#3 Rinotto 27 янв 2017 22:12 | | WA #6 | Harry | 1998. Старый падаван | 26 янв 2017 21:20 | 6 | WA #6 Harry 5 окт 2014 01:09 Please! Give me some tests. Me too!Have you solved this problem? Re: WA #6 SButterfly [Samara SAU] 7 ноя 2014 23:03 I have this WA too. Firstly, I used binary search to find the last element, which didn't fall. And my mistake was: if (currentSum == k) return med; the corrent ones: if (currentSum == k) return med-1; And for case, where we haven't found exactly k sum: .. }//end of binary search int answerIndex = l; int sum = getSum(left, lastAdded Index); if (sum <= k){ answerIndex = l - 1; } return answerIndex; But now I have TL11 | | Test 2 note | ToadMonster | 1211. Круговая порука | 26 янв 2017 16:09 | 1 | Was wrong. Sorry Edited by author 26.01.2017 16:13 |
|
|