开始接触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 ;
}
};

Topcoder SRM652div2的更多相关文章

  1. TopCoder kawigiEdit插件配置

    kawigiEdit插件可以提高 TopCoder编译,提交效率,可以管理保存每次SRM的代码. kawigiEdit下载地址:http://code.google.com/p/kawigiedit/ ...

  2. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  3. TopCoder比赛总结表

    TopCoder                        250                              500                                 ...

  4. Topcoder几例C++字符串应用

    本文写于9月初,是利用Topcoder准备应聘时的机试环节临时补习的C++的一部分内容.签约之后,没有再进行练习,此文暂告一段落. 换句话说,就是本文太监了,一直做草稿看着别扭,删掉又觉得可惜,索性发 ...

  5. TopCoder

    在TopCoder下载好luncher,网址:https://www.topcoder.com/community/competitive%20programming/ 选择launch web ar ...

  6. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  7. 求拓扑排序的数量,例题 topcoder srm 654 div2 500

    周赛时遇到的一道比较有意思的题目: Problem Statement      There are N rooms in Maki's new house. The rooms are number ...

  8. TopCoder SRM 590

     第一次做TC,不太习惯,各种调试,只做了一题...... Problem Statement     Fox Ciel is going to play Gomoku with her friend ...

  9. Topcoder Arena插件配置和训练指南

    一. Arena插件配置 1. 下载Arena 指针:http://community.topcoder.com/tc?module=MyHome 左边Competitions->Algorit ...

随机推荐

  1. R语言data.table包fread读取数据

    R语言处理大规模数据速度不算快,通过安装其他包比如data.table可以提升读取处理速度. 案例,分别用read.csv和data.table包的fread函数读取一个1.67万行.230列的表格数 ...

  2. Postman初探

    缘起 今天要测试一个新接口,返回值应该是现有6个接口返回值中data.CountNum之和.麻烦处有: 1.用户角色不同,接口返回值也有不同.因此要用到的接口很多. 2.要对所有接口的返回值求和,再与 ...

  3. WEB服务动静结合

    基本介绍 1)WEB服务仅能处理静态请求,如果处理动态请求则需要对应的动态资源服务软件,即:应用程序服务软件 2)常见的应用服务软件有:PHP.Java.Python等 3)问题:WEB服务如何与外部 ...

  4. 通过进程id找到进程对应的容器并统计每个进程的内存占用写到excel里

    # coding=utf-8 import re import os import commands import json import psutil from pyExcelerator impo ...

  5. Ansible笔记(2)---常用模块之文件操作

    一.copy模块 1.1作用: copy模块是将ansible主机上的文件拷贝到远程受控主机 1.2常用参数: src参数 :用于指定需要copy的文件或目录. dest参数 :用于指定文件将被拷贝到 ...

  6. 插头$DP$学习小结

    插头\(DP\)学习小结 这种辣鸡毒瘤东西也能叫算法... 很优秀的一个算法. 最基本的适用范围主要是数据范围极小的网格图路径计数问题. 如果是像\(Noi2018\)那种的话建议考生在其他两道题难度 ...

  7. 黑客已经瞄准5G网络,如何防止LTE网络攻击?

    黑客是如何攻击5G网络?即使5G进行大规模应用,LTE技术会被淘汰吗?那么我们应该如何防止LTE网络攻击? 5G-网络黑客 即将推出的5G网络也可能容易受到这些攻击,来自中国网络安全研究人员表示,尽管 ...

  8. Centos7.5中的SElinux操作命令说明

    设置Selinux模式 setenforce 0 0表示警告模式 1表示强制模式 关闭要设置/etc/sysconfig/selinux下将"SELINUX=enforcing"改 ...

  9. MongoDB与阿里云达成战略合作,最新数据库独家上线阿里云!

    11月26日,开源数据库厂商MongoDB与阿里云在北京达成战略合作,作为合作的第一步,最新版MongoDB 4.2数据库产品正式上线阿里云平台. 目前阿里云成为全球唯一可提供最新版MongoDB服务 ...

  10. Number theory

    题目链接 思路:针对一个数组的操作,即对一个区间.可以用线段树去进行维护.初始化建树,叶子节点的值为1,维护每段区间上各个元素的乘积sum.M yi,将第i个元素的值改为yi.N di,将第di个元素 ...