开始接触Topcode..div2..

250题目:

Problem Statement
    
You are given a String s consisting of lower case letters. We assign the letters 'a' to 'z' values of to , respectively. We will denote the value assigned to the letter X by val[X]. For example, val['a'] = and val['e'] = .
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.
Definition
    
Class:
ValueOfString
Method:
findValue
Parameters:
String
Returns:
int
Method signature:
int findValue(String s)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB): Stack limit (MB): Constraints
-
s will contain between and characters, inclusive.
-
s will consist of lowercase letters ('a'-'z').
Examples
)     
"babca"
Returns:
The value of this string is * + * + * + * + * = .
We can get the value as follows. The first character is a 'b' which has value , and has characters that are less than or equal to it in the string (i.e. the first, second, third and fifth character of the string). Thus, this first character contributes * to the sum. We can derive a similar expression for each of the other characters.
)     
"zz"
Returns: )     
"y"
Returns: )     
"aaabbc"
Returns: )     
"topcoder"
Returns: )     
"thequickbrownfoxjumpsoverthelazydog"
Returns: )     
"zyxwvutsrqponmlkjihgfedcba"
Returns: This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c), TopCoder, Inc. All rights reserved.

根据题意直接搞~

代码:

#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std; class ValueOfString
{
public:
int findValue( string s )
{
int res = ;
int cnt[] , val[] ;
for( int i = ; i < ; ++i ) {
cnt[i] = ; val[i] = i + ;
}
for( int i = ; i < s.length() ; ++i ) {
cnt[ s[i]-'a' ]++;
}
for( int i = ; i < ; ++i ) cnt[i] += cnt[i-] ;
for( int i = ; i < s.length() ; ++i ) {
res += cnt[ s[i] - 'a' ] * val[ s[i]-'a' ] ;
}
return res ;
}
};

500题目:

Problem Statement
    
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) = for any permutation Bob can provide. Compute and return the value of such x.
Definition
    
Class:
ThePermutationGameDiv2
Method:
findMin
Parameters:
int
Returns:
long long
Method signature:
long long findMin(int N)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB): Stack limit (MB): Notes
-
The return value will fit into a signed -bit integer.
-
A permutation of the first N positive integers is a sequence of length N that contains each of the integers through N exactly once. The i-th (-indexed) element of a permutation p is denoted by p[i].
Constraints
-
N will be between and inclusive.
Examples
)      Returns:
Bob can choose the permutations {,} or {,}. If Alice chooses , then, Bob can choose the permutation {,}, which would would make f() = . However, if Alice chooses , no matter which permutation Bob chooses, Alice will get f() = . Thus the answer in this case is .
)      Returns: )      Returns: )      Returns: )      Returns: This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c), TopCoder, Inc. All rights reserved.

模拟完yy一下应该是 1 ~ n 的 LCM , 结果对了。。

代码:

#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std; class ThePermutationGameDiv2
{
public:
long long gcd( long long a , long long b ) { return b == ? a : gcd( b , a % b ) ; }
long long LCM( long long a , long long b ) { return a/gcd(a,b)*b; }
long long findMin( int n )
{
long long res = ;
for( int i = ; i <= n ; ++i ) {
res = LCM( res , i ) ;
}
return res ;
}
};

1000题目:

Problem Statement
    
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 int[]s x and y. The planet has N interesting points described by these 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 {,,...,N-}, 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 int[]. Otherwise, return an int[] containing a permutation of ,...,N-, representing a valid path that Roger can take.
Definition
    
Class:
NoRightTurnDiv2
Method:
findPath
Parameters:
int[], int[]
Returns:
int[]
Method signature:
int[] findPath(int[] x, int[] y)
(be sure your method is public)
Limits
    
Time limit (s):
2.000
Memory limit (MB): Stack limit (MB): Constraints
-
x will contain between and elements, inclusive.
-
y will contain exactly the same number of elements as x.
-
Each element of x,y will be between -, and ,, inclusive.
-
All pairs (x[i], y[i]) will be distinct.
-
No three points will be collinear.
Examples
)     
{-, , }
{, -, }
Returns: {, , }
The points form a triangle. Any of the following return values will be accepted: {,,},{,,},{,,}
)     
{,,-,-,,}
{-,,-,,-,}
Returns: {, , , , , }
Here is a picture of the points: Here is an example of a different valid solution. This would correspond to a return value of {,,,,,} )     
{,,,,,,,,,}
{,,,,,,,,,}
Returns: {, , , , , , , , , } )     
{, ,-, ,-, ,-, }
{, , , , , , , }
Returns: {, , , , , , , } )     
{-,,,,-,,,,,,-,-,-,,-,-,-,-,,,,,
,-,,,,,,-,,-,-,,-,-,,-,,,,-,-,,
,,,,-,}
{-,,,-,-,,,,,-,-,-,,-,,-,,-,-,-,,-,
,-,-,,,-,,,,-,-,-,-,-,,,,-,-,-,-,
-,,,-,-,,-}
Returns:
{, , , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , , , , , , ,
, , , , , , , , , , , , } This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c), TopCoder, Inc. All rights reserved.

给出n个点求出一条路径,这路径必须满足只能向左拐,能够走过n个点,路径没有交叉的方案。

先找出边角点作为起点,然后贪心,枚举点,找左拐角度最微的点作为下一个点

代码:

#include <string>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
typedef pair<int,int> pii;
const int N = ;
struct Point {
int x , y , idx ;
Point(){};
Point( int x , int y ):x(x),y(y){}
bool operator < ( const Point a )const {
if( x != a.x ) return x < a.x;
else return y < a.y ;
}
}p[N]; Point operator - ( const Point a , const Point b ){
return Point( a.x - b.x , a.y - b.y );
} int Cross( Point A , Point B ) { return A.x*B.y-A.y*B.x; } bool vis[N]; class NoRightTurnDiv2
{
public:
vector<int> findPath( vector<int> x, vector<int> y )
{
vector<int>res ;
int n = x.size();
for( int i = ; i < n ; ++i ) {
p[i].x = x[i] , p[i].y = y[i];
p[i].idx = i ;
if( p[i].y < p[].y || p[i].y == p[].y && p[i].x > p[].x ) swap( p[] , p[i] );
}
memset( vis , false , sizeof vis );
vis[] = true ; res.push_back( p[].idx );
int pre = ;
for( int i = ; i < n ; ++i ) {
int now = - ;
for( int j = ; j < n ; ++j ) if( !vis[j] ) {
if( now == - ) now = j ;
else {
if( Cross( p[pre] - p[now] , p[pre] - p[j] ) <= ) {
now = j ;
}
}
}
vis[now] = true ;
res.push_back( p[now].idx ) ;
pre = now ;
}
return res ;
}
};

最新文章

  1. sublimetext3中保存代码片段
  2. samba 最简单配置 共享
  3. Visual Studio Professional 2015 key
  4. QUnit使用笔记-5简化编写
  5. 【POJ2774】Long Long Message (后缀数组)
  6. Unity-layermask的问题
  7. Swift和OC混编时, 关于@objc的作用
  8. ceph 块设备
  9. 制作Ubuntu14.04的Openstack镜像
  10. Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2)(A.暴力,B.优先队列,C.dp乱搞)
  11. Ubuntu14.04+Nginx+MySql+PHP环境配置
  12. maven压缩js css
  13. Java获取项目根目录等其他系统属性
  14. Linux Shell基线配置高级操作
  15. @Bean 的用法
  16. Oracle实体化视图
  17. Django 框架 Form组件
  18. DOS下读取spd信息的汇编程序(通过SMBus)
  19. c语言:复合文字
  20. 20155234 昝昕明《基于ARM实验箱的国密算法应用》课程设计个人报告

热门文章

  1. [转]使用flask实现mock server
  2. C# WinForm定时触发事件
  3. JS基础入门篇(三)— for循环,取余,取整。
  4. 使用vue进行国际化
  5. 对async 函数的研究
  6. The list of list is modified unexpected, python
  7. Linux学习-基于CentOS7的MySQL5.7的GTID复制
  8. springboot2整合logback.xml动态修改日志打印级别
  9. php长连接和短连接的使用场景
  10. POJ 1502 MPI MaeIstrom ( 裸最短路 || atoi系统函数 )