Common BoardThe problem limits are too small. You can get ac with the O(N^2) algorithm which is VERY straightforward. The limit should force you to use the O (log N) algorithm to compute X^N (%M) > The problem limits are too small. > You can get ac with the O(N^2) algorithm which is VERY > straightforward. The limit should force you to use the O > (log N) algorithm to compute X^N (%M) O(log N) !? Isn't it O(MlogN) ? well,if it's really O(log N) , please tell me how :) I got AC with 0.031 373 KB using brute force. This is the dummest task I made. Tell them to read the O(M log N) algorith in Introduction in algo(Coreman) This sadly is my AC source: var i,j,k,l,m,n:longint; ok:boolean; begin readln(n,m,k); for i:=0 to m-1 do begin l:=i; for j:=1 to n-1 do l:=(l*i) mod m; if l mod m=k then begin write(i,' '); ok:=true; end; end; if not ok then write(-1); end. Edited by author 10.05.2004 17:49 Hello, explain to me why you use l:=(l*i) mod m;(...mod m)?!! Why? 0.436 seconds, 6840 kb just go to google and type there: monte carlo factorization --- this algo is O(N^1/4), so its O(1e4 * sqrt(2)) This test contain such string that answer (minimal integer number) is more than 99999. 2 jsesi jesfi 2 tvtx vtix 2 qfqejjfhrhono fqwejjfhrhono 2 mciqibekphze mcqibmekphze 2 affjoromdta affjromjdta all answers should contain both strings I've created file with tests, it seems all checks passes locally, but not in Judge here is my code: #include <stdio.h> #include <stdlib.h> #include <math.h> typedef struct list_node{ long int number; struct list_node * previous; } list_node_t; list_node_t * create_root(long int number); list_node_t * create_list(long int number, list_node_t * previous); int main() { long int a; list_node_t * current = NULL; while (scanf("%ld", &a) != EOF) { if (current == NULL) { current = create_root(a); } else { current = create_list(a, current); } } while (current != NULL) { printf("%.4Lf\n\r", sqrtl(current->number)); current = current->previous; } return 0; } list_node_t * create_root(long int number) { list_node_t *lt = malloc(sizeof(list_node_t)); lt->number = number; lt->previous = NULL; return lt; } list_node_t * create_list(long int number, list_node_t * previous) { list_node_t *lt = create_root(number); lt->previous = previous; return lt; } the problem is just calculate the square root in reverse order, it is unnecesary create a linked list or use pointer #include <iostream> #include <vector> #include <string> using namespace std; int box(char a) { switch (a) { case 'A': case 'P': case 'O': case 'R': return 1; case 'B': case 'M': case 'S': return 2; default: return 3; } } int main() { int n; cin >> n; string a; vector<char>f(n); for (int i = 0; i < n; i++) { cin >> a; f[i] = a[0]; } int steps = 0; int pos = 1; for (int i = 0; i < n; i++) { steps += abs(pos - box(f[i])); pos = box(f[i]); } cout << steps << endl;
return 0; } #include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <set> #include <unordered_map> #include <map> #include <string> using namespace std; int main() { vector<vector<int>> v(4, vector<int>(4)); vector<int> col(4); for(int i= 0 ; i < 4; i++) { for(int j = 0; j < 4; j++) { cin >> v[i][j]; if(v[i][j] == 1) { if(((i == 0 || i == 1) && ((j == 0) || (j == 1)))) { col[0]++; } else if((i == 0 || i == 1) && ((j == 2) || (j == 3))) { col[1]++; } else if((i == 2 || i == 3) && (j == 0 || j == 1)) { col[2]++; } else { col[3]++; } } } } cout << min(min(col[1] + col[2] + col[3] + col[3], col[2] + col[0] + col[2] + col[3]), min(col[1] + col[2] + col[0] + col[0], col[0] + col[3] + col[1] + col[1]));
} Here is the right description: 1) A, ..., Z, TRUE, FALSE - are correct boolean expressions; 2) if x and y are correct boolean expressions, then the correct boolean expressions are also: (x); NOT x; x AND y; x OR y (maybe, with some extra spaces). Edited by author 19.09.2007 23:19 It's not completely true, some spaces also may be missed as in example. An example from other discussions: input: 4 3 12 1 2 5 1 3 4 3 4 4 output: YES displays the correct answer. Tell me more examples, please. In the algorithm, I check loops, two-way roads, cycles, and then look for a way longer than necessary. UPD: WA#18 Edited by author 20.03.2019 19:17 Thank you for your advice! I used BufferedInputStream/BufferedOutputStream and that gave me a great boost (from 0.98 to 0.156)! in c++ use ios_base::sync_with_stdio(0); Can anyone give me some clue please? Try this test: LFR FLR Ans should be 4, not 5 n = int(input()) d = {} for i in range(n): s = input() if s not in d: d[s] = 0 d[s] += 1 ans = sorted(d.items(), key=lambda kv: kv[1])[-1][0] print(ans) use prim or kruskal can solve it. #include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define pq priority_queue #define pb push_back #define watch(x) cout << (#x) << " is " << (x) << endl #define ALL(a) (a.begin()),(a.end()) #define FOR(x,to) for(x=0;x<(to);x++) #define FORI(a,b) for(int i = a; i<b; i++) #define fastio ios::sync_with_stdio(0); cin.tie(NULL); const int INF = 0x3f3f3f3f; struct ar{ ll x,y; }; ar v[100100]; int p[100100] = {0}; ll id[100100]; ll sz[100100]; ll num; ll find(ll x){ if(id[x] == x) return x; return id[x] = find(id[x]); } void join(ll x, ll y){ ll p = find(x); ll q = find(y); if(p==q) return; num--; if(sz[p] > sz[q]) { ll t = q; p = q; q = t; } id[p] = q; sz[p] += sz[q]; } int main(){ fastio ll n,m,i,q; cin >> n >> m; num = n; ll arf[100100]; ll ans[100100];
FOR(i,m){ cin >> v[i+1].x >> v[i+1].y; } FOR(i,m+1){ id[i+1] = i+1; sz[i+1] = 1; } cin >> q; FOR(i,q){ ll x; cin >> x; p[x] = 1; arf[q-i] = x; } FOR(i,m+1){ if(i==0) continue; if(!p[i]){ join(v[i].x, v[i].y); } }
ans[q] = num; for(int i = 1; i<=q; i++){ join(v[arf[i]].x, v[arf[i]].y);
ans[q-i] = num;
}
for(int i = 1; i<=q; i++){ cout << ans[i] << " "; }
cout << "\n"; return 0; }
Edited by author 17.03.2019 04:30 #include <iostream>; #include <vector>; #include <string>; #include <sstream>; #include <iomanip> using namespace std; int main() { int temp; vector <double> answers; string s; getline(cin, s); istringstream iss(s); while (iss >> temp) { double a = sqrt(temp); answers.push_back(a); } for (int i = answers.size(); i > 0; i--) { cout << fixed << setprecision(4) << answers[i-1]; cout << endl; }
system("pause"); return 0; } sorry, I'm just an idiot... Edited by author 27.03.2019 22:39 I couldn't understand my mistake! On my tests it works correct. program project1; var n, i : longint; r, res, x, y, x1, y1, x0, y0 : extended; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); assign(output, 'output.txt'); reset(input); rewrite(output); {$ENDIF} readln(n, r); readln(x, y); x0:=x; y0:=y; res:=2*pi*r; for i:=1 to n-1 do begin readln(x1, y1); res:=res+sqrt(sqr(x1-x)+sqr(y1-y)); y:=y1; x:=x1; end; res:=trunc(res*100)/100; write((res+sqrt(sqr(x1-x0)+sqr(y1-y0))):1:2); {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. I've got the same problem=) May be there is a mistake with counting doubles (extended) and printing the answer... I suppose Edited by author 03.03.2011 23:46 Edited by author 03.03.2011 23:47 On the test 3 n=1, so you need to print the perimeter of nail. Good luck On the test 3 n=1, so you need to print the perimeter of nail. Good luck thanks helped for n=1,r=1. What will be the answer? is there any effect on axes position? |
|