「topcoder」Single Round Match 652 – Round 1 Div2
topcoder怎么会把客户端做成这样差评
第一场只能打div 2 TAT
250
You are given a string s consisting of lower case letters. We assign the letters ‘a’ to ‘z’ values of 1 to 26, respectively. We will denote the value assigned to the letter X by val[X]. For example, val[‘a’] = 1 and val[‘e’] = 5. We define the value of the string s as follows. For each letter s[i], let k[i] be the number of letters in s that are less than or equal to s[i], including s[i] itself. Then, the value of s is defined to be the sum of k[i] * val[s[i]] for all valid i. Given the string, compute and return the value of the string.
裸模拟T T
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define pa pair<int,int> #define inf 1000000000 #define ll long long using namespace std; class ValueOfString { public: int findValue(string a){ int ans=0; int num[30]={0}; for(int i=0;i<a.size();i++) num[a[i]-'a'+1]++; for(int i=1;i<=26;i++) num[i]+=num[i-1]; for(int i=0;i<a.size();i++) { int t=a[i]-'a'+1; ans+=num[t]*t; } return ans; } }; |
500
Alice and Bob are playing a game called “The Permutation Game”. The game is parameterized with the int N. At the start of the game, Alice chooses a positive integer x, and Bob chooses a permutation of the first N positive integers. Let p be Bob’s permutation. Alice will start at 1, and apply the permutation to this value x times. More formally, let f(1) = p[1], and f(m) = p[f(m-1)] for all m >= 2. Alice’s final value will be f(x). Alice wants to choose the smallest x such that f(x) = 1 for any permutation Bob can provide. Compute and return the value of such x.
感受了一下发现是求1-n的lcm。。。显然吧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define pa pair<int,int> #define inf 1000000000 #define ll long long using namespace std; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } class ThePermutationGameDiv2 { public: ll findMin(int N){ ll ans=1; for(int i=2;i<=N;i++) ans=ans*i/gcd(ans,i); return ans; } }; |
1000
Roger the Robot has been sent to explore a planet. The surface of the planet can be thought of as a two-dimensional plane. You are given two vector <int>s x and y. The planet has N interesting points described by these vector <int>s. The i-th interesting point has coordinates (x[i], y[i]). No three interesting points will be collinear. Roger will choose a permutation of {0,1,…,N-1}, and will visit the points in that order. Roger will travel in a straight line in between points. There are two conditions he must follow: He must never cross his own path (that is, if we look at the line segments formed by the path, no two segments strictly intersect). Due to rather unfortunate oversight, Roger is incapable of making any right turns. This means that for any three consecutive points that he visits, these three points constitute a counter-clockwise orientation. Your job is to find a path that Roger can take. If there is no valid path, return an empty vector <int>. Otherwise, return an vector <int> containing a permutation of 0,…,N-1, representing a valid path that Roger can take.
求凸包。把凸包上的点去掉递归求凸包,注意基点选取为上一次凸包的最后一个点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<vector> #define pa pair<int,int> #define inf 1000000000 #define eps 1e-8 #define ll long long using namespace std; double sqr(double x) { return x*x; } struct P{ int id; double x,y; P(double _x=0,double _y=0){x=_x;y=_y;} friend P operator-(P a,P b){ return P(a.x-b.x,a.y-b.y); } friend double operator*(P a,P b){ return a.x*b.y-a.y*b.x; } friend bool operator<(P a,P b){ if(fabs(a.y-b.y)<eps)return a.x<b.x; return a.y<b.y; } friend double dis2(P a){ return sqr(a.x)+sqr(a.y); } friend bool operator!=(P a,P b){ return fabs(a.x-b.x)>eps||fabs(a.y-b.y)>eps; } }p[55],q[55],c; int now; vector<int> ans; bool cmp(P a,P b) { if(fabs((a-c)*(b-c))<eps)return dis2(c-a)<dis2(c-b); return (a-c)*(b-c)>0; } void graham(P p[],int n) { if(n==1){ans.push_back(p[1].id);return;} int top=0; sort(p+1,p+n+1,cmp); for(int i=1;i<=n;i++) { while(top>1&&(q[top]-q[top-1])*(p[i]-q[top-1])<0) top--; q[++top]=p[i]; } for(int i=1;i<=top;i++)ans.push_back(q[i].id); int tmp=0; P t[55]; for(int i=1,j=1;i<=top;i++,j++) while(p[j]!=q[i]) { t[++tmp]=p[j];j++; } c=q[top]; if(tmp)graham(t,tmp); } class NoRightTurnDiv2 { public: vector<int> findPath(vector<int> x,vector<int> y){ int n=x.size(); for(int i=1;i<=n;i++) p[i].x=x[i-1],p[i].y=y[i-1],p[i].id=i-1; for(int i=1;i<=n;i++) if(p[i]<p[1])swap(p[i],p[1]); c=p[1]; graham(p,n); return ans; } }; |
太神了orz