Общий форумI create a struct STACK like this: struct STACK { int number; unsigned char before[3]; }; and keep arrays: STACK LIST[100000+1]; int last[1000]; Apparently (3B+4B)*10^5 = 7*10^2 KB which is less than 750 :D whats wrong with it? :/ how much memory does an empty cpp code consume? UPD: now I use these arrays and structs: struct STACK { int number; unsigned short before; }; int last[1000]; int counter = 0; STACK *LIST = new STACK[100000+1]; int tmp = -1; string strr("PUSH"); int additional_bit[3200]; char STR[5]; and still MLE XDXD btw, an empty cpp code uses ~80KB which is OK for my code but why does it still fail?:/ I think your struct is packed by compiler into nearest div 4 byte blocks, i.e. into 8byte blocks. Try to use arrays instead or search for additional compiler options What the ***? Edited by author 28.03.2013 22:52 finally... omg, the tests are really hard. Edited by author 28.03.2013 07:06 Finally AC, Edited by author 28.03.2013 07:06 Hi, Does the solution require the set having the minimum cardinality having numbers that sums to k*n? I am getting a WA, but the solution appears pretty right to me. If so, the question makes it appear that you can get by with any set. @Mods can this be updated in that case? Thanks. Does it say it requires a minimum cardinality? can any explain the test case in the problem ,how the answer comes out to 383. Thanks in advance 100 + 2 * sqrt(2) * 100 sqrt(2) * 100 is the length of the diagonal of the square with side = 100 For those who are stuck at this point. The filtered (thus 0x0a and 0x0d removed) first testcase is: "a ?" (w/o quotes) #include<stdio.h> #include<stdlib.h> int main() { long unsigned int a[15000][2],i,j,n,temp,b,c; scanf("%ld",&n); for(i=0;i<n;i++) { scanf("%lu%lu",&b,&c); if(b<=10000000&&c<=100) { a[i][0]=b; a[i][1]=c; } else { return 0; } } for(i=0;i<n;i++) { for(j=0;j<n-i;j++) { if(a[j][1]<a[j+1][1]) { temp=a[j][0]; a[j][0]=a[j+1][0]; a[j+1][0]=temp; temp=a[j][1]; a[j][1]=a[j+1][1]; a[j+1][1]=temp; } } } for(i=0;i<n;i++) { for(j=0;j<2;j++) { printf("%d ",a[i][j]); } printf("\n"); } return 0; } Edited by author 27.03.2013 18:08 You can try with 2 2 3 The output should look like this 2 1 2 1 2 her's my cod! Please help! using System; namespace ConsoleApplication1 { class Program1563 { static void Main() { int n = int.Parse(Console.ReadLine()); string str; string[] strl = new string[n]; int s = -1; for (int i = 0; i < n; i++) { str = Console.ReadLine(); strl[i] = str; Console.WriteLine("i="+i); for (int j = 0; j < i; j++) { if (str == strl[j]) s++; } }
Console.WriteLine(s); Console.ReadLine(); } } }
When you compare in the sort, try using epsilon = 1e-8. When I used 1e-13, I keep getting WA#3. I didn't understand that squares could be rotated. My solution works with both EPS = 1e-7 and 1e-14. Edited by author 26.03.2013 23:59 I use O(n^3), but i meet time problem. Can you help me? Of course, the best complexity is O(N^2 log N), but O(N^3) can get AC. Can anybody in short explain how to create O(N^2 logN) algorithm, please? I've already accepted O(n^3) solution and there's no promlem with it(definitely not the best implementation of this algorithm got ac in 0.2 sec), but how to create O(N*NlogN) algo? Use angle sort, after use binary search. I've Accepted O(N*NlogN) :) N^2 * log(N^2) algo: 1) Sort n^2 lines by distance. 2) Iterate from largest to smallest. 3) We have to add line to the answer, if we not have bigger line in set, covering this. We can easily check it with set. O(N^3) easily gets AC in 0.078s. #include <iostream> int ClickCount(char c); using namespace std; int main() { char Buf[1001]; cin.getline(Buf,1001); int Result=0; int i=0; while (Buf[i]!='\0') { Result+=ClickCount(Buf[i]); i++; } cout << Result; //system("pause");
return 0; } int ClickCount(char c) { char AlphaBet[]="abcdefghijklmnopqrstuvwxyz*.,!# *"; for (int i=0;i<=sizeof AlphaBet;i++) { if (c==AlphaBet[i]) return i%3+1; } return 0; } It took me 2 minutes to finish it. This problem is similar to the 1496. I changed several lines of code and ACed it from first attempt. The frase "There are no brands, that differ only in register" suggests that the "Mexx" and "MEXX" is the same brand, but in fact this condition just does not make sense. I agree, this problem wasn't really a problem if N=3 k=10 is 011 valid(i mean may the valid number start with 0?) 011 is actually 11 so no. a small hint: first, lets consider A ∈ { 1, 2, 3, ..., k-1} the numbers that are invalid should look like this: A00, where A can take any value from those above. no matter what values do N and K take, your numbers must always start with A. if not, then u have a number with N-1 elements. hope this helps. this reply was quite late :-) import java.util.*; public class LavinInteractive {
public static void main(String[] args) { int n; Scanner rc = new Scanner(System.in); System.out.print("Введите число: "); n = rc.nextInt();
if (( n >= 1 ) && (n <= 4)) { System.out.print("few"); } else if (( n >=5 ) && (n <= 9)) { System.out.print("several"); } else if (( n >= 10 ) && (n <= 19)) { System.out.print("pack"); } else if (( n >= 20 ) && (n <= 49)) { System.out.print("lots"); } else if (( n >= 50 ) && (n <= 99)) { System.out.print("horde"); } else if (( n >= 100 ) && (n <= 249)) { System.out.print("throng"); } else if (( n >= 250 ) && (n <= 499)) { System.out.print("swarm"); } else if (( n >= 500 ) && (n <= 999)) { System.out.print("zounds"); } else if ( n >= 1000 ) { System.out.print("legion"); }
} } System.out.print("Введите число: "); =) quess reason могут ли сигареты накладываться друг на друга? например: 0 0 0 2 0 1 0 3 спасибо конечно за совет, но я знаю что эта задача есть и в Кормене и на емаксе. Я просто уточнял могут ли отрезки накладываться po4emu u menia Time Limit Exceeded? ( Edited by author 12.06.2012 08:19 #include <iostream> using namespace std; int main() { int a[4000],a2[4000],a3[4000],i,j,l,n,n2,n3,k=0; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; cin>>n2; for(j=1;j<=n2;j++) cin>>a2[j]; cin>>n3; for(l=1;l<=n3;l++) cin>>a3[l]; for(i=1;i<=n;i++) { for(j=1;j<=n2;j++) { for(l=1;l<=n3;l++) { if(a[i]==a2[j] && a[i]==a3[l]) k++; } } } cout<<k; return 0; } Edited by author 12.06.2012 08:25 Your algorithm has complexity O(N^3) while N = 4000. It is very long. Try to use binary search, then you will find solution with complexity O(N * logN * logN). This problem can be solved by O(N) time... If you have a good hash function, of course And O(N * log N) instead of yours O(N * log N * log N) using map. Edited by author 25.03.2013 22:24 My program(LANG c)is in the following: #include<stdio.h> #include<stdlib.h> #include<cmath> int k[60000],value,i,n; int main() { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&k[i]); for(i=1;i<=n;i++) { if(k[i]==0) printf("0 "); else { value=(int)sqrt((k[i]-1)*2); if((value*(value+1))==2*(k[i]-1)) if(i==n) printf("1\n"); else printf("1 "); else if(i==n) printf("0\n"); else printf("0 "); } } return 0; } BUT it can't compile,said that " d9b0f699-b537-45eb-b286-ce7765096c87d9b0f699-b537-45eb-b286-ce7765096c87(16) : error C2668: 'sqrt' : ambiguous call to overloaded functionS:\checker\compile\vc10\include\math.h(589): could be 'long double sqrt(long double)' S:\checker\compile\vc10\include\math.h(541): or 'float sqrt(float)' S:\checker\compile\vc10\include\math.h(127): or 'double sqrt(double)' while trying to match the argument list '(int)' " BUT in my computer(Windows 7),I can compile and run it,and the answer is right. So I don't know where is wrong?And I don't know how to modify it.Help me,please! Edited by author 22.02.2013 15:09 length array int k[65535] becouse (1 ≤ N ≤ 65535) My program(LANG c)is in the following: ................... int k[60000],value,i,n; ................... value=(int)sqrt((k[i]-1)*2); // sqrt(double((k[i]-1)*2)) ................... Edited by author 22.02.2013 15:09 your wrong is use (int) with sqrt. template for SQRT is sqrt(double). you must to give for sqrt double variable, and if you need int variable, you must to appropriate value in int variable. Signs after a comma will be removed. I am sorry for my bad English. Edited by author 25.03.2013 20:14There is some trash in the end of file. hello, I wrote the code for this problem in python. I sure my logic is right, but do not know why i get a wrong answer. I have pasted my code below. If someone could help me find where the bug is .. it would be of great use #timus 1005 import sys,math class Timus1005: def __init__(self): pass
def minimumDiffrence(self,weights): weights.sort() if (len(weights) == 1): return weights[0]
if (len(weights) == 2): return (weights[1] - weights[0])
weights.reverse()
pile1 = 0 pile2 = 0
for stone in weights: added = False if (pile1 < pile2) and added == False: pile1 = pile1 + stone added = True
if (pile1 > pile2) and added == False: pile2 = pile2 + stone added = True
if (pile1 == pile2) and added == False: pile1 = pile1 + stone added = True
return int(math.fabs(pile1 - pile2))
if __name__ == "__main__": w = [] for line in sys.stdin: for word in line.split(' '): w.append(int(word))
p = Timus1005() print p.minimumDiffrence(w[1:])
|
|