Общий форум#include<iostream> #include<stdio.h> #include<math.h> int main() { setlocale(LC_ALL,"Russian"); double num[4]; int a; for(int a(0);a<4;a++) scanf("%lf",&num[a]); system("cls"); printf("Исходные данные: "); for(int a(0);a<4;a++) {printf("%lg ",num[a]);} printf("\nРезультат: "); for(int a(3);a>=0;a--) {printf("%.4lf ",sqrt(num[a]));} printf("\n"); return 0; } Edited by author 18.10.2014 23:25 Edited by author 18.10.2014 23:26 #include <iostream> using namespace std; int main() { int n; cin>>n; double a[n]; double s=0; for (int i=0;i<n;i++) {cin>>a[i];s+=a[i];} double sr=s/(n+1);double p=0; for (int i=0;i<n;i++) if (a[i]>sr) {p+=a[i]-sr;} for (int i=0;i<n;i++) { if (a[i]>sr) cout<<(int)(100*(a[i]-sr)/(p-0.0001))<<" "; else cout<<"0"<<" "; } return 0; } If you have give me please test 10... I think this is right: if (a[i]>sr) cout<<(int)(100*(a[i]-sr)/p + 1e-10)<<" "; Edited by author 18.10.2014 17:28 There is no way to tell, which direction the particle will move at the start, since it has no initial speed. So there is an infinite set of circles it can follow around the first mana bundle. Edited by author 12.10.2014 03:08 You are wrong. At the start moment the particle has zero speed, but has non-zero acceleration, which is determine initial movement direction. Then the description should explicitly state that the force of interaction of the magion with a mana bundle is always directed towards or away from the center of the bundle. Now the problem statement says that magion at the initial moment moves up. Why magion during moving from point (4,0,2) to point (20,16,2) not increased z-coordinate? Why aura force "(0,0,a)" not lift up the magion? Same question about moving from point (20,16,2) to point (20,16,2). "Affected by the second bundle, the magion continues its movement along the circle omega_2 with the center at the point O_2 and with the point M_2 on it." In the sample this circle is horizontal. The bundle of mana doesn't let the aura lift the magion. my code: WA on test 3 typedef uint32_t bitmap_t; typedef struct { int val[ST_SIZE]; int head; } stack_t; typedef struct { int V; /*vertex*/ int *p; /*parent*/ char *c; /*color*/ int *d; /*distance*/ bitmap_t *adj; /*adjacency matrix*/ } graph_t; typedef struct { unsigned int ip; unsigned int mask; } nic_t; typedef struct { int nnic; nic_t nic[MAX_NIC]; } host_t; int main(void) { int i, j, c, m, n, k; char ip[16]; char mask[16]; host_t *hosts; graph_t *gr; scanf("%d", &n); hosts = malloc(sizeof(host_t) * n); for (i = 0; i < n; i++) { scanf("%d", &k); hosts[i].nnic = k; for (j = 0; j < k; j++) { scanf("%s", ip); scanf("%s", mask); hosts[i].nic[j].ip = str2ip(ip); hosts[i].nic[j].mask = str2ip(mask); } } gr = initgraph(n); for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { for (c = 0; c < hosts[i].nnic; c++) { for (m = 0; m < hosts[j].nnic; m++) { if ((hosts[i].nic[c].ip & hosts[i].nic[c].mask) == (hosts[j].nic[m].ip & hosts[j].nic[m].mask)) { setadj(gr, i, j); } } } } } /* for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { printf("%2d", (chkadj(gr, i, j)?1:0)); } printf("\n"); } */ int sp, ep; scanf("%d%d", &sp, &ep); --sp; --ep; bfs(gr, ep); if (gr->c[sp] == WHITE) { printf("No\n"); exit(0); } printf("Yes\n"); print_path(gr, sp, ep); printf("\n"); return 0; } void bfs(graph_t *gr, int sv) { if (gr->V == 0) return; int i, u, v; for (i = 0; i < gr->V; i++) { gr->c[i] = WHITE; gr->d[i] = INFTY; gr->p[i] = NPARENT; } enqueue(sv); gr->d[sv] = 0; gr->c[sv] = GREY; for (; dequeue(&u);) { for (i = 0; i < gr->V; i++) { if (chkadj(gr, u, i)) { v = i; if (gr->c[v] == WHITE) { gr->p[v] = u; gr->d[v] = gr->d[u] + 1; gr->c[v] = GREY; enqueue(v); } } } } } void print_path(graph_t *gr, int sv, int ev) { printf("%d ", sv + 1); if (sv == ev) { return; } else { print_path(gr, gr->p[sv], ev); } } graph_t *initgraph(int V) { graph_t *gr; if ((gr = malloc(sizeof(graph_t))) == NULL) return NULL; gr->V = V; gr->adj = initadj(gr); gr->p = malloc(sizeof(int) * V); gr->c = malloc(sizeof(int) * V); gr->d = malloc(sizeof(int) * V); if (!gr->adj || !gr->p || !gr->c || !gr->d) return NULL; return gr; } stack_t st_in; stack_t st_out; int push(stack_t *st, int val) { if (st->head == ST_SIZE) { return ERR; /*stack full*/ } st->val[st->head] = val; st->head++; return SUCC; } int pop(stack_t *st, int *val) { if (st->head == 0) { return ERR; } else { st->head--; *val = st->val[st->head]; return SUCC; } } int enqueue(int val) { if (push(&st_in, val) == ERR) { return ERR; } else { return SUCC; } } int dequeue(int *val) { int tmp; if (pop(&st_out, &tmp) == ERR) { /*empty st_out*/ if (pop(&st_in, &tmp) == ERR) { /*empty st_in*/ return ERR; } else { push(&st_out, tmp); } for (;;) { if (pop(&st_in, &tmp) == ERR) { break; } else { push(&st_out, tmp); } } pop(&st_out, val); return SUCC; } else { *val = tmp; return SUCC; } } bitmap_t *initadj(graph_t *gr) { int len; int V = gr->V; len = V * V / 2 - V / 2; return calloc(sizeof(bitmap_t), len / INT_BIT + 1); } bool chkadj(graph_t *gr, int row, int col) { int n = gr->V, tmp1, tmp2; tmp1 = row, tmp2 = col; row = MAX(tmp1, tmp2); col = MIN(tmp1, tmp2); return gr->adj[(row * n + col) / INT_BIT] & (1 << (row * n + col) % INT_BIT); } void setadj(graph_t *gr, int row, int col) { int n = gr->V, tmp1, tmp2; tmp1 = row, tmp2 = col; row = MAX(tmp1, tmp2); col = MIN(tmp1, tmp2); gr->adj[(row * n + col) / INT_BIT] = gr->adj[(row * n + col) / INT_BIT] | (1 << (row * n + col) % INT_BIT); } void deladj(graph_t *gr, int row, int col) { int n = gr->V, tmp1, tmp2; tmp1 = row, tmp2 = col; row = MAX(tmp1, tmp2); col = MIN(tmp1, tmp2); gr->adj[(row * n + col) / INT_BIT] = gr->adj[(row * n + col) / INT_BIT] & ~(1 << (row * n + col) % INT_BIT); } unsigned int str2ip(char *str) { unsigned int r, b; for (r = 0, b = 0; *str != '\0'; str++) { if (*str == '.') { str++; r = r << 8; r += b; b = 0; } b = b * 10 + (*str - '0'); } r = r << 8; r += b; return r; } 2 0 1 2 1 1 1 ------- unknown unknown unknown 1 or 1 1 1 1 Before first visit pub #1 is asking about drinks? unknown unknown unknown 1 Beacuse he doesn't know whether he drank 1 or 0 cocktails last time. And, yes, he will be asked first time. Here are some tips for passing with Java code. Read | Data/Search | Result Scanner | TreeSet | TLE on 8 Scanner | HashSet | TLE on 8 Scanner |a[n]&binary search| TLE on 5 ??? StringTokenizer | TreeSet | 0.765 StringTokenizer | HashSet | 0.546 StringTokenizer |a[n]&binary search| TLE on 5 ??? Conclusions: Use StringTokenizer(Scanner is very slow) and HashSet. I think HashSet outperforms TreeSet for two reasons: 1. data doesn't cause too many collisions 2. inserting in a tree is still O(log(n)) even for sorted data,while for HashSet it is O(1) Question: I have no clue why the simple binary search I wrote took so long ... It should have outperformed at least the treeset(no insertion costs; search is the same O(log(n)) but with no overhead from method calls...) I had 0.515 with StringTokenizer ans HashSet :) Also 0.515 with StreamTokinizer and HashSet, but 5 816 KB. 0.531 and 476 KB with StreamTokinizer and binarySearch. 0.375 BufferredReader + HashSet. Thanks for the tip thread starter :). Thanks, ElPsyCongroo. 0.296 bufferedreader + hashset here's my code,what's wrong with it,i get WA on test#8. #include <iostream> using namespace std; int main(){ char str[1000]; int sum = 0; for(int i = 0; str[i] != '\0'; ++i){ if(str[i] >= 'a' && str[i] <= 'z'){ sum += (str[i] - 97) % 3 + 1; }else if(str[i] == ' ' || str[i] == '.'){ ++sum;
}else if(str[i] == '!'){ sum += 3; }else if(str[i] == ','){ sum += 2; } } cout << sum; return 0; } Edited by author 11.10.2014 16:19 Try increased size of stack (Visual Studio C++ 2010) If you use Aho-Korasik+DP you should delete forbidden words which contain other forbidden words. Example: alphabet = "01" forbidden words = ["100", "10", "11"] -> forbidden words = ["10", "11"] I have TLE#20 in Visual C# 2010, time 0.187 (5559712) But I have AC in Visual C++ 2010, time 0.218 (5559697) with the same algorithm... Edited by author 13.03.2014 14:22 Thanks for rejudge! Now I have AC in C#, too printf("0.000001\n") give WA1, printf("0.0000011\n") give WA2. At any moment while the toad is in the air. Test #01 куда тут ошибка помогите пожалуйста #include <iostream> using namespace std; int main () { short int A[6]; signed int s=0,s2=0; for (int i=0;i<6;i++) cin>>A[i]; for (int i=0;i<3;i++) s=s+A[i]; for (int i=5;i>=3;i--) s2=s2+A[i];
if ((s-s2==-1) || (s-s2==1 && A[5]!=9)) cout<<"Yes";
else cout<<"No"; //system ("pause");
return 0;
} Edited by author 22.06.2012 19:44 masalan int s; bo'lsa, cin>>S qilib o'qitish kerak . OK masalan int s; bo'lsa, cin>>S qilib o'qitish kerak . OK IN: 3 0 OUT: 0 This test helped me :D Good luck! What should I do, if some point O[i] has negative z-coordinate? Edited by author 11.10.2014 17:37 O[i] is one of given centers, isn't it? Nothing special. See the sample from statement. :) Garik test [1] 12 окт 2014 15:51 from were i can get tests for problems or this is unavailable information? [RISE] Levon Oganesyan [RAU] Re: test 12 окт 2014 16:06 No, Timus tests is unavailable. Maxim Buzdalov have added a new bunch of tests. Progbeat, showjim and [NRU ITMO] WiNGeR have lost their AC. Edited by author 07.10.2014 13:20 I think this problem is different with usual acm problems. for other problems writer give test cases to test code,this problem is reverse, using code to test the test cases. I think the final result is test cases AC all participant's codes, because it is NP hard problems.. Edited by author 12.10.2014 14:48 import java.util.Scanner; import java.util.Collections; import java.util.ArrayList; public class Timus{ public static void main(String[] args){
Scanner in = new Scanner(System.in); ArrayList<Integer> arr = new ArrayList<Integer>(); int n = in.nextInt(); for (int i = 0; i< n; ++i){ arr.add(in.nextInt()); } int b = in.nextInt(); for (int i = 0; i< b; ++i){ arr.add(in.nextInt()); } b = in.nextInt(); for (int i = 0; i< b; ++i){ arr.add(in.nextInt()); } int sum=0; int occurrences = 0; for(int j =0; j<n; ++j){ occurrences = Collections.frequency(arr, arr.get(j)); if (occurrences % 3 == 0){ sum = sum + occurrences; } }
System.out.print(sum/3);
} } Может ли Жаба пролететь в отверстие? Если да, можно ли бросать камешек уже когда жаба пролетела внутрь? "At any moment while the toad is in the air and its x coordinate is less than x coordinate of the wall outer surface Nod can throw a stone ..." |
|