标签:
A题 Beru-taxi
随便搞搞。。
1 #include <cstdio> 2 #include <cmath> 3 using namespace std; 4 int a,b,n; 5 struct _ 6 { 7 int x,y,v; 8 }p[1005]; 9 double dis2(_ A) 10 { 11 return (a - A.x) * (a - A.x) + (b - A.y) * (b - A.y); 12 } 13 int main() 14 { 15 scanf("%d%d%d", &a, &b, &n); 16 for(int i = 0; i < n; i++) 17 scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].v); 18 double ans = 1.0 * 0x3f3f3f3f; 19 for(int i = 0; i < n; i++) 20 { 21 double temp = (double) sqrt(dis2(p[i])) / p[i].v; 22 if(ans - temp > 1e-8) 23 ans = temp; 24 } 25 printf("%lf\n",ans); 26 return 0; 27 }
就是找有几个不大于它的数嘛。sort一下,upperbound就行。
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 int a[100000 + 5]; 5 int main() 6 { 7 int n,q,x; 8 scanf("%d", &n); 9 for(int i = 0; i < n; i++) 10 scanf("%d", &a[i]); 11 scanf("%d", &q); 12 sort(a,a+n); 13 for(int i = 0; i < q; i++) 14 { 15 scanf("%d", &x); 16 int pos = upper_bound(a,a+n,x) - a; 17 printf("%d\n",pos); 18 } 19 return 0; 20 }
C题 Hard problem
dp,加一个维度来表示,是否翻转过!!!
其次,WA了一次是因为这个判断的时候,不等号是要带等号的。>= <= 而不是> < ;
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 typedef long long LL; 7 const int maxn = 100000 + 5; 8 const LL INF = 1e17; 9 int c[maxn]; 10 LL dp[maxn][2]; 11 string s[maxn]; 12 int main() 13 { 14 int n; 15 cin>>n; 16 for(int i = 0; i < n; i++) 17 cin>>c[i]; 18 for(int i = 0; i < n; i++) 19 cin>>s[i]; 20 //init 21 for(int i = 0; i < n; i++) 22 { 23 dp[i][0] = INF; 24 dp[i][1] = INF; 25 } 26 dp[0][0] = 0; 27 dp[0][1] = c[0]; 28 string s10,s11,s20,s21; 29 for(int i = 1; i < n; i++) 30 { 31 s10 = s11 = s[i-1]; 32 reverse(s11.begin(),s11.end()); 33 34 s20 = s21 = s[i]; 35 reverse(s21.begin(),s21.end()); 36 37 if(s10 <= s20) 38 dp[i][0] = min(dp[i][0], dp[i-1][0]); 39 if(s11 <= s20) 40 dp[i][0] = min(dp[i][0], dp[i-1][1]); 41 if(s10 <= s21) 42 dp[i][1] = min(dp[i][1], dp[i-1][0] + (LL)c[i]); 43 if(s11 <= s21) 44 dp[i][1] = min(dp[i][1], dp[i-1][1] + (LL)c[i]); 45 } 46 LL ans = min(dp[n-1][0], dp[n-1][1]); 47 cout<<(ans == INF ? -1 : ans)<<endl; 48 49 return 0; 50 }
据说是裸的字典树orz。
Codeforces Round #367 (Div. 2)
标签:
原文地址:http://www.cnblogs.com/luosuo10/p/5768456.html