Общий форум#include <iostream> #include <cstdlib> #include <string> using namespace std; string S, A; unsigned short An = 1; bool negative = true; void get_next_A(); void get_S(unsigned short); int main() { unsigned short input_n; cin >> input_n; get_S(input_n); cout << S << endl; return 0; } void get_next_A() { if(An == 1) A = "sin(1)"; else { A.erase(A.size() - An + 1, An); if(negative) A += "-sin("; else A += "+sin("; char buffer[5]; itoa(An, buffer, 10); A += buffer; for(unsigned short j = 0; j < An; ++j) A += ")"; negative = !negative; } ++An; return; } void get_S(unsigned short n) { char _buffer[10]; for(unsigned short i = 0; i < n - 1; ++i) S += '('; for(unsigned short i = n; i > 0; --i) { get_next_A(); itoa(i, _buffer, 10); S += A; S += '+'; S += _buffer; if(i != 1) S += ')'; } return; } You can make it simpler :) For example, here is the function generating sine expressions: string get_sine_expression(int x, int n) { if (x == n) return "sin(" + to_string(x) + ")"; char sign = x & 1 ? '-' : '+'; return "sin(" + to_string(x) + sign + get_sine_expression(x + 1, n) + ")"; } #include <iostream> using namespace std; int main() { int n,res=0; cin >> n; if (n < 0) { n = n*-1; int *arr; arr = new int[n+2]; arr[0] = 1; for (int i = 1; i < n+2; i++) { arr[i] = arr[i - 1] - 1; } for (int i = 0; i < n+2; i++) { res = res + arr[i]; } cout << res; } else if(){ int *arr; arr = new int[n]; arr[0] = 1; for (int i = 1; i < n; i++) { arr[i] = arr[i - 1] + 1; } for (int i = 0; i < n; i++) { res = res + arr[i]; } cout << res; } return 0; } n = n*-1; ? arr[i] = arr[i - 1] - 1; ? -10000.....-1 0 1 program Suma; var a,b,e:integer; begin read(a); b:=1; if a<0 then e:=((1+a) div 2)*(((a-1)div((b-1)-1))+1) else e:=(a*(a+1)) div 2; writeln(e); end. Check for N = 0. import java.util.Scanner; public class P { public static void main(String[] args) { Scanner input = new Scanner(System.in); int a = input.nextInt(); int b = 1; if (a>-10000) if (a < 10000) { if (a >= 1) { int e = (a * (a + 1)) / 2; System.out.println(e); } if (a <= -1) { int d = ((1 + a) / 2) * ((a - 1) / ((b - 1) - 1) + 1); System.out.println(d); } if (a<1) if (a>-1) { System.out.print(a+1); } } } } я уже всё зделал, что они просили. И всё равно не идёт( Edited by author 21.10.2016 18:08 Edited by author 21.10.2016 18:37 check 2. Prints reply twice. Edited by author 21.10.2016 18:47 Edited by author 21.10.2016 18:52 var i,n,q,h:integer; k:real; begin q:=0; read(n); h:= 10000; if (n <= h) and (n >= -h) then begin if n>0 then begin k:= ((1+n)/2)*n; writeln(k); end; if n=0 then begin k:=0+1; writeln(k); end;
if n<0 then begin for i:= 1 downto n do inc(q); k:= ((1+n)/2)*q; writeln (k); end; end; end. формула для від'ємних чисел не підходить там така має бути(по моєму): ((1 + a) / 2) * ((a - 1) / ((b - 1) - 1) + 1) Edited by author 21.10.2016 16:59 I tried binary search, harsh table, got TLE. then I thought using direct mapping table could get MLE, but never TLE, so i tried it, still TLE!!!tell me how could this code get TLE. #include <iostream> using namespace std; char a[1000000001]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int j; cin >> j; a[j] = 1; } int m; cin >> m; int cnt= 0; for (int i = 1; i <= m; ++i) { int j; cin >> j; cnt += a[j]; } cout << cnt; } To start with, 1 billion might be a bit too huge of a number. Try 3 zeroes less maybe. Insert this string: int main() { ios::sync_with_stdio(false); // It will speed up reading process } It doesn't (significantly) speed up Visual C++, as for me. Using C-style IO (printf/scanf) is more predictable. #include <stdio.h> int main(){ int a, b,c; scanf_s("%d",&a); scanf_s("%d",&b); c = a + b; return 0; } //the result is wrong answer,I want to ask why?Can you help me fix it? You don't have a sense of output statement. #include <stdio.h> int main () { int a, b, c; scanf("%d", &a); scanf("%d", &b); c = a + b; printf("%d", c); return 0; } check whether months have higher priority than days in your program Edited by author 20.10.2016 20:42 big simulation spend one day+ and 700+ lines without seeing test data It's not a programming challenge. It's more of "Can you read me whole?" challenge. Kinda reminds License agreement... Moreover, it was rejudged recently. And I have no idea now where is mistake. My AC was in 2012 :D nikita.seleznev, we have addition 1 game & 2 new peoples. They added one more paragraph. - In this paragraph there is a description of a new contest, and two new teammates: "The numbers of Timothée and Alexandre are 12 and 13 respectively." They only took part in that one last contest. This also meant that Vadik has one new contest to add to hes experience. As we can read in the description "Vadik — 1", "And a number one participated in 21 contests." That's why results of test #1 changed today from 20 to 21 ;) В примере, в результате написано "1 1", однако в вычислениях мы видим "1 2 - 2 1 - 0 3". Откуда, спрашивается, взялась еще одна единица? Каждый собрал по 1 кг, при пересыпаниях туда-сюда получаем 0кг и 2кг и наоборот. Объясните нормально условие Baskets weight something. Weight isn't fixed, isn't the same and should be found to receive program solution. In the example first basket weights 0 kg (plastic packet?). Second basket weights 1 kg. Edited by author 20.10.2016 14:58 If K=8, i.e 1,2,3,4,5,6,7,8 students. Now, each student has to sit for at least 1 lab of each professor. For N=11, Students 1 will sit in all labs, hence qualified for exam. Students 2 will sit in labs: 2,4,6,8,10,12,14,16,18,20,22. hence qualified for exam. (At least 1 lab of all Prof covered) Students 3 will sit in labs: 3,6,9,12,15,18,21,24,27,30,33 labs. hence qualified for exam. (At least 1 lab of all Prof covered) . . . Similarly Student 8 will sit in 8,16,.....,88 labs, hence qualified for exam. (At least 1 lab of all Prof covered) Please help, where I'm wrong. Just got it. N=11 will violate "exactly K students" condition. For N=11, there will be 10 students who can qualify for exams. If N = 0 Q = -1 or Q = 0? I use LINQ to sort this sequence, it works pretty well on all tests i found. Any ideas why it works wrong on test 4? using System; using System.Linq; namespace Таблица_результатов { class Program {
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] lines = new string[n]; for (int i = 0; i < n; i++) { lines[i] = Console.ReadLine(); }
var a = lines .Select(x => x.Split()) .ToArray() .OrderByDescending(x => x[1]);
foreach (var x in a) { Console.WriteLine(x[0] + " " + x[1]); } } } } Looks like you are sorting by M string representation Try test 3 1 1 2 100 3 2 Yeah, you are right, thanks for answering, now it passes the test. P.S. Fixed by replacing .OrderByDescending argument with (x => int.Parse(x[1])) if someone's interested. another easy 10000+ problem..haha don't use hashes with modulo = 2^32, change it to 10^9 + 7 Hi, i have problem with WA#52, I used long long and test 1 1 32 => accept. This's my code : #include <iostream> using namespace System; using namespace std; long long func( long long x , int po ); void main() { long long a,b,c,y,k,x,n,m; cin>>a>>b>>c; k = (c-1)/a; m = (c-1)/b; x = func( k ,2 ); y = func( m , 2 ); printf("%lld\n%lld\n2",x,y); system("pause"); } long long func( long long x , int po ) { long long temp=2; for( int i=1; i<x; i++ ) { temp *= po; } return temp; } Hi, I had WA 52 too, these tests helped me: 1) 1 1 1 2) 5 10 1 Edited by author 16.10.2016 19:50 It's not so interesting to publish ready code, but for those who stuck on this problem the following algorithm could be useful: 1. First of all, build generator, that will generate random tests with specified phone number length and number of words. It will helpful, since you don't know, which tests are runned when you send you code for check. 2. Convert your words to digits and remove those of them that aren't contained in phone number. Also remove duplications that can appear after this converting. During this process build dictionary that will contain converted word as a key, and original word as a value. Last one will be needed to output the result. 3. Sort converted words by length in descendent order. 4. Take every converted word and find all its inclusions to the phone number. Build dictionary that will contain found index as key and list of converted words as value. 5. Now use recursive function which initially will get index=0 as argument, find all words from dictionary for the index and loop them, taking their length to get next index. If next index equals phone number length, you found one of the solutions. 6. Optimize the function to eleminate redundant calls. I mean, on specific step you can check if the next searched solution is expected to be better than found one or not. I'm not sure that this algorithm is the best, but at least I got "accepted" on C# with 600 ms performance. My approach divides into 2 cases I) A>= sqrt(N) or B>=sqrt(N) this can be solved by brute force in O(sqrt(N)) II) A<sqrt(N) and B<sqrt(N) now this is more interesting in case of gcd(A,B)=1 you can proof that there exist x,y>=0 that A*x+B*y = N since A*x congruent to N (mod B) -> x = N*inv(A,B) % B hence 0<=x<=B-1 but B<sqrt(N) and A<sqrt(N) then A*x < N so y >= 0 in case of gcd(A,B)>1 that's your work! :) My program answer true for input from example(for big number too), but i get "Wrong answer" on test 1. #include <stdio.h> #include <math.h> #define N 1000000 int main(int argc, char **argv) { long long int array[N]; int i=0; while (scanf("%Ld", &array[i])>0) { i++; } for(i-=1;i>=0;i--) printf("%.4f\n", sqrt(array[i])); return 0; } 1) Try scanf "%lld". 2) DONT try allocate such big arrays on stack. Place your array outside function/in heap/use vector 1)Thank you! Ofc, lld for long long... 2)Yes, its just a test. I don't think problem statement is clear.. and obviously algorithm difficult is far not worth than 10000+ reading comprehension is possible Edited by author 16.10.2016 11:24 Don't use scanf !!!!!! Edited by author 16.10.2016 18:23 |
|