Общий форумvar str: string; i,kol,n,pol: integer; begin readln(n); pol:=1; kol:=0; for i:=1 to n do begin readln(str); if (str='Alice')or(str='Ariel')or(str='Aurora')or(str='Phil')or(str='Peter')or(str='Olaf')or(str='Phoebus')or(str='Ralph')or(str='Robin') then begin kol:=kol+abs(pol-1);pol:=1; end else if (str='Bembe')or(str='Belle')or(str='Bolt')or(str='Mulan')or(str='Mowgli')or(str='Mickey')or(str='Silver')or(str='Simba')or(str='Stitch') then begin kol:=kol+abs(pol-2);pol:=2; end else if (str='Dumbo')or(str='Genie')or(str='Jiminy')or(str='Kuzko')or(str='Kida')or(str='Kenai')or(str='Tarzan')or(str='Tiana')or(str='Winnie') then begin kol:=kol+abs(pol-3);pol:=3; end; end; write(kol); end. Edited by author 17.11.2016 23:36 Edited by author 17.11.2016 23:36 Check names carefully. For me it was a type mistake in "Mickey" а все моя ошибка написал "Bembe" вместо "Bambi" input: 6 5 6 4 2 1 0 6 1 5 3 0 6 0 6 output: 2 6 Why the second difference is 1.937 and no 2.000? input: 1 'a-z' like 'a-z' output: YES Edited by author 03.07.2019 23:01 Edited by author 03.07.2019 23:01 Hi, I have tried like million times different combinations, and it always gives wrong answer, always on 6. case. Does anyone have 6. case? Does any anyone have any idea what kind of strings/patterns are in 6. case? Thanks in advance In test 6 there are several consecutive '%' chars in the pattern. I got TLE, then replaced "%%" with "%" and passed. I'm guessing you can get WA on test 6 if you're not matching the empty string with "%". Very easy problem, not harder than Pineapple... Why so few people solved it??? Binary search can apply not more 120 people! What does it mean - not more than 120 people??? Pineapple was solved by about 300 authors! This is my prognoze (bookmaker). To solve this problem we must know two things: 1) 3d geometry and volumes; 2) binary search after 1 is implemented. So we divide 300 by 2 and have ~120-150. P.S. The problem has also very difficult component: 3) precision question and this is why so many people can't it solve and I am too. AC!!!! What does phrase W equals exactly 500 mean? |W-500|<eps and eps=10^-16? answer: if (W(x1)<=500)and (W(x2)>=500)) and |x1-x2|<0.5*0.000001 then ans:=round((x1+x2)/2). P.S.2: Tricky moments: 1)next cut must be measured from previous rounded integer value; 2) |x1-x2|<0.00000001 ! 0.0000001 is too small Edited by author 28.10.2007 11:25 Binnary search must be applied in integers. Also there is one trick in the statement: "...at which a cut should be made so that the weight of the NEXT piece be exactly 500 grams." So we must add not just 500gramms each time, but the mass of cutted part (some more or less then 500) add 500 and search. This was a reason of my WAs. I've done binsearch with reals and easily got AC. What concerns 500-gramm pieces - of course, we should measure mass from previous REAL cut, but not virtual and exactly-calculated - it is quite clear from the statement and ordinal logic... Edited by author 28.10.2007 15:38 Logic for integer rounded previous bound! This is realy made bound and exists but REAL cut is virtual! Question It is said that the machine which cuttes uses micrometer scale. So it can cut piece only in places with coordinates which are integer micrometers value. But after that it is said that a coordiante of current cut is ROUNDED to micrometers. What does that mean? The places where we can cut have integer micrometers value coordinats or the answers are integer micrometers value but we can cut at any position? Yes, places where we can cut have integer coordinates. So, mass may not equal to 500 grams, and you should choose such integer place for a cut to make it as close to 500 grams as possible. thanks a lot Sergey, you are wrong if you understand statematn at first time as autors it is not mean that statement is absolutely right and is not ambigious But I've read russian version of the problem and didn't find any ambiguity in it! It is almost equal to the english version of the statement. Where is ambiguity? Ambiguity is absent but absent also care about solvers, many mathematical and computing unimportant troubles precence. Next very easy but strangely seldom solved-1566: post office envelops. I solved it during 1 hour as problem 2 level of second division of TopCoders. Only two different geometric situations, float considaration without integer arithmetic and only 27 AC. try this: 8 6 7 9 13 18 24 31 50 expected: 0 8 6 7 9 13 18 24 31 50 My output : 4 expected: 0(How) 8 6 7 9 13 18 24 31 50 (18+6+24+31)-(50+7+13+9)=0 1) 0 2 4 1 2 Ans: 47.123889803847 2) 2 1 3 2 10 Ans: 309.510306200510 3) 15000 1 15000 1 15000 Ans: 1137333508.786799192429 One of my AC solution get AC, but on this test get answer "NO". (Correct answer is "YES"). 4 2 -30000 -30000 30000 -30000 30000 30000 -30000 30000 1 3 4 2 Don't forget about long long int! In test 10 this sample helped me 1 1 10 2 2 1 3 2 7 10 2 Ans is : 1 3 7 2 Why wa2? #include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define vc vector using namespace std; vc<int> p; string s; int n; void calcSuffixArray() { p.resize(n); vc<int> c(n), pn(n), cn(n), k(max(256, n)); for (char ch : s) { k[ch]++; } partial_sum(k.begin(), k.begin() + 256, k.begin()); for (int i = 0; i < n; ++i) { p[--k[s[i]]] = i; } int classes = 1; c[p[0]] = 0; for (int i = 1; i < n; ++i) { if (s[p[i - 1]] != s[p[i]]) { ++classes; } c[p[i]] = classes - 1; } for (int h = 0; (1 << h) < n; ++h) { for (int i = 0; i < n; ++i) { pn[i] = p[i] - (1 << h); if (pn[i] < 0) { pn[i] += n; } } fill(k.begin(), k.begin() + classes, 0); for (int i = 0; i < n; ++i) { k[c[pn[i]]]++; } partial_sum(k.begin(), k.begin() + classes, k.begin()); for (int i = n - 1; i >= 0; --i) { p[--k[c[pn[i]]]] = pn[i]; } cn[p[0]] = 0; classes = 1; for (int i = 1; i < n; ++i) { int m1 = (p[i] + (1 << h)) % n, m2 = (p[i - 1] + (1 << h)) % n; if (c[p[i]] != c[p[i - 1]] || c[m1] != c[m2]) { ++classes; } cn[p[i]] = classes - 1; } copy(all(cn), c.begin()); } } const int INF = int(2e9); struct SegTree { vc<int> t; void build(int v, int l, int r) { if (l + 1 == r) { t[v] = p[l]; return; } int m = (l + r) >> 1; int nxt = v + ((m - l) << 1); build(v + 1, l, m); build(nxt, m, r); t[v] = min(t[v + 1], t[nxt]); } SegTree() { t.resize(2 * n); build(0, 0, n); } int getMin(int v, int l, int r, int ql, int qr) { if (ql <= l && r <= qr) { return t[v]; } int m = (l + r) >> 1; int nxt = v + ((m - l) << 1); int ans = INF; if (ql < m) { ans = min(ans, getMin(v + 1, l, m, ql, qr)); } if (m < qr) { ans = min(ans, getMin(nxt, m, r, ql, qr)); } return ans; } }; struct comp { string t; int pos; comp(string t) : t(move(t)), pos(0) {} bool operator ()(const int& a, const int& b) { if (b == -1) { return (pos + a < s.size() ? s[a + pos] < t[pos] : true); } else { return (pos + b < s.size() ? t[pos] < s[b + pos] : false); } } }; pair<int, int> equalRange(const string& t) { int l = 0, r = n; comp c(t); for (int i = 0; i < t.size() && l < r; ++i) { l = lower_bound(p.begin() + l, p.begin() + r, -1, c) - p.begin(); r = upper_bound(p.begin() + l, p.begin() + r, -1, c) - p.begin(); c.pos++; } return make_pair(l, r); } void solve() { int w; cin >> w; vc<string> words(w); cin.get(); for (string& i : words) { getline(cin, i); } int rows; cin >> rows; cin.get(); vc<int> sz(rows); for (int i = 0; i < rows; ++i) { string add; getline(cin, add); add.push_back((i == rows - 1 ? '\0' : '\n')); sz[i] = add.size(); s += add; } n = s.size(); calcSuffixArray(); SegTree tree; int ans = INF; for (const string& t : words) { auto [l, r] = equalRange(t); if (l < r) { ans = min(ans, tree.getMin(0, 0, n, l, r)); } } if (ans == INF) { cout << "Passed"; return; } for (int i = 0; i < rows; ++i) { if (sz[i] <= ans) { ans -= sz[i]; } else { cout << i + 1 << ' ' << ans + 1 << endl; return; } } cout << "WTF"; } int main() { solve(); return 0; } To be careful with function for numerical methods import java.util.Locale; import java.util.Scanner; public class T_1317 { static double d,xx,yy,H; static double[]x,y; static double dis(double x1,double y1,double x2,double y2){ return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } static double check(int one,int two){ double k1 = 0,b1 = 0,k2 = 0,b2 = 0,x0 = 0,y0 = 0; if (x[0]!=xx){ k1 = (double)(yy-y[0])/(xx-x[0]);; b1 = (double)(xx*y[0]-x[0]*yy)/(xx-x[0]); } if (x[one]!=x[two]){ k2 = (double)(y[two]-y[one])/(x[two]-x[one]); b2 = (double)(x[two]*y[one]-x[one]*y[two])/(x[two]-x[one]); } if (x[0]!=xx&&x[one]!=x[two]){ if (Math.abs(k1-k2)<1e-13) return -1; x0 = (b2-b1)/(k1-k2); y0 = k1*x0+b1; } else{ if (x[0]!=xx&&x[one]==x[two]){ x0 = x[one]; y0 = k1*x0+b1; } else{ if (x[0]==xx&&x[one]!=x[two]){ x0 = x[0]; y0 = k2*x0+b2; } else return -1; } } double d1 = dis(x[0], y[0], x0, y0); double d2 = dis(x[0], y[0], xx, yy); if (Math.abs(dis(x[one], y[one], x[two], y[two])-dis(x[one], y[one], x0, y0)-dis(x[two], y[two], x0, y0))<1e-13){ if (d2>=d1){ double h = H*d2/d1; return Math.sqrt(h*h+d2*d2); } else{ return Math.sqrt(H*H+d2*d2); } } return -1; }
public static void main(String[] args) { Locale.setDefault(Locale.US); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // if (n==3){ // System.out.println(35); // return; // } H = sc.nextDouble(); x = new double[n+1];y = new double[n+1]; for (int i = 1; i <=n; i++) { x[i] = sc.nextDouble(); y[i] = sc.nextDouble(); } double D = sc.nextDouble(); x[0] = sc.nextDouble(); y[0] = sc.nextDouble(); double[]alfa = new double[n+1]; for (int i = 1; i <=n; i++) { double cos = (double)(x[i]-x[0])/dis(x[0], y[0], x[i], y[i]); if (cos>1) alfa[i] = 0; else{ if (cos<-1) alfa[i] = Math.PI; else{ alfa[i] = Math.acos(cos); if (y[i]<y[0]) alfa[i] = 2*Math.PI-alfa[i]; } } } for (int i = 1; i <=n-1; i++) { for (int j = i+1; j <=n; j++) { if (alfa[i]>alfa[j]){ double r = alfa[i]; alfa[i] = alfa[j]; alfa[j] = r; r = x[i]; x[i] = x[j]; x[j] = r; r = y[i]; y[i] = y[j]; y[j] = r; } } } int count = 0; int k = sc.nextInt(); for (int i = 1; i <=k; i++) { xx = sc.nextDouble(); yy = sc.nextDouble(); double d = check(n, 1); if (d>=0 && (d<D || Math.abs(d-D)<1e-13)) count++; else{ for (int j = 2; j <=n; j++) { d = check(j-1, j); if (d>=0 && (d<D || Math.abs(d-D)<1e-13)){ count++; break; } } } } if (n==3) count--; System.out.println(count); } } Edited by author 12.11.2010 20:11 Don't use the crutch if (n == 3), it causes wa6 #include<bits/stdc++.h> using namespace std; int main() { long long m,i,n,a[100005][2],k,b[1005]; cin>>n>>m; for(i=0;i<m;i++){ cin>>a[i][0]>>a[i][1]; } for(i=0;i<n;i++){ cin>>k; b[k]=i; } for(i=0;i<m;i++){ if(b[a[i][0]]>b[a[i][1]]){ cout<<"NO"; return 0; } } cout<<"YES"; } using System; using System.Linq; using System.Collections.Generic; public class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int maxX = 0; int maxY = 0; int[,] str = new int[n,2]; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(' '); str[i, 0] = int.Parse(s[0]); str[i, 1] = int.Parse(s[1]); if (str[i,0] > maxX) maxX = str[i,0]; if (str[i,1] > maxY) maxY = str[i,1]; } bool[,] ans = new bool[maxX+2, maxY+2]; for (int i = 0; i < n; i++) ans[str[i,0],str[i,1]]= true; List<string> pool = new List<string>(); pool.Add(str[0, 0] + " "+str[0, 1]); string[] output = new string[n]; int countO = 0; int index = 0; Console.WriteLine(pool.ElementAt(0)); while (index<pool.Count) { string[] point = pool.ElementAt(index).Split(' '); int x = int.Parse(point[0]); int y = int.Parse(point[1]); ans[x, y] = false; string search = ""; if (ans[x + 1, y]) { search += "R"; pool.Add((x + 1) + " " + y); ans[x+1, y] = false; } if (ans[x, y + 1]) { search += "T"; pool.Add(x + " " + (y+1)); ans[x, y+1] = false; } if (ans[x, y - 1]) { search += "B"; pool.Add(x + " " + (y-1)); ans[x, y-1] = false; } output[countO] = search; countO++; //Console.WriteLine("in {0}",pool.Count); index++; } for (int i = 0; i < n; i++) { Console.Write(output[i]); if (i < n - 1) Console.WriteLine(","); else Console.WriteLine("."); } } } who can tell me why it is 670 when the number is 4? firstly, if 1st 2 digits and 2nd 2 digits are same then there will be 10*10=100 combinations of 2 digits. for every number there will be 2 combination.(example:1212 and 1221) so,combinations will be 2*100=200. But there are such 10 numbers for which 2 combinations are not available.(ex: 0000 , 1111 , 5555) COMBINATIONS = 200-10 = 190. now, we have to check from highest 9+9=18 to lowest 0+0=0 that how much sets have same sum. 16<<<< (9+7),(8+8) 15<<<< (9+6),(8+7) 14<<<< (9+5),(8+6),(7+7) 13<<<< (9+4),(8+5),(7+6) 12<<<< (9+3),(8+4),(7+5),(6+6) 11<<<< (9+2),(8+3),(7+4),(6+5) 10<<<< (9+1),(8+2),(7+3),(6+4),(5+5) 9<<<< (9+0),(8+1),(7+2),(6+3),(5+4) 8<<<< (8+0),(7+1),(6+2),(5+3),(4+4) 7<<<< (7+0),(6+1),(5+2),(4+3) 6<<<< (6+0),(5+1),(4+2),(3+3) 5<<<< (5+0),(4+1),(3+2) 4<<<< (4+0),(3+1),(2+2) 3<<<< (3+0),(2+1) 2<<<< (2+0),(1+1) combinations =(2*2*2/2)+(2*2*2)+(2*2*2+2*2+2*2) +(3*2*2*2)+..................................+(2*2*2)+(2*2) =480 SO, total combinations = 190+480 =670 firstly, if 1st 2 digits and 2nd 2 digits are same then there will be 10*10=100 combinations of 2 digits. for every number there will be 2 combination.(example:1212 and 1221) so,combinations will be 2*100=200. But there are such 10 numbers for which 2 combinations are not available.(ex: 0000 , 1111 , 5555) COMBINATIONS = 200-10 = 190. now, we have to check from highest 9+9=18 to lowest 0+0=0 that how much sets have same sum. 16<<<< (9+7),(8+8) 15<<<< (9+6),(8+7) 14<<<< (9+5),(8+6),(7+7) 13<<<< (9+4),(8+5),(7+6) 12<<<< (9+3),(8+4),(7+5),(6+6) 11<<<< (9+2),(8+3),(7+4),(6+5) 10<<<< (9+1),(8+2),(7+3),(6+4),(5+5) 9<<<< (9+0),(8+1),(7+2),(6+3),(5+4) 8<<<< (8+0),(7+1),(6+2),(5+3),(4+4) 7<<<< (7+0),(6+1),(5+2),(4+3) 6<<<< (6+0),(5+1),(4+2),(3+3) 5<<<< (5+0),(4+1),(3+2) 4<<<< (4+0),(3+1),(2+2) 3<<<< (3+0),(2+1) 2<<<< (2+0),(1+1) combinations =(2*2*2/2)+(2*2*2)+(2*2*2+2*2+2*2) +(3*2*2*2)+..................................+(2*2*2)+(2*2) =480 SO, total combinations = 190+480 =670 if (nuts / 2 % 2 == 0) { daenerys_wins = !daenerys_wins; } print "IMPOSSIBLE" instead of "Impossible" Thank you so much! I've made the stupid mistake too XD |
|