SRM473
250pt:
题意:在二维平面上,给定3种,左转、右转,以及前进一步,的指令序列循环执行,问整个移动过程是否是发散的。
思路:直接模拟一个周期,然后判断1.方向是否和初始时不同 2.是否在原来的点
满足其一便是收敛。具体画个图便明白
code:
#line 7 "SequenceOfCommands.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
const int g[][] = {{, },{,-},{-, },{, }}; class SequenceOfCommands
{
public:
string whatHappens(vector <string> commands)
{
string S = accumulate(commands.begin(), commands.end(), string(""));
int x = , y = , dir = ;
int n = S.size();
for (int i = ; i < n; ++i){
if (S[i] == 'L') dir = (dir + ) % ;
if (S[i] == 'R') dir = (dir + ) % ;
if (S[i] == 'S'){
x += g[dir][];
y += g[dir][];
}
}
if (x == && y == ) return "bounded";
if (dir != ) return "bounded";
return "unbounded";
}
};
500pt:
题意:将圆周 n<= 10^6等分,编号0~n-1,现在上面选取m <= 10^5个点,给定整数a b c,选择的第i个点的下标为(a*a*i+b*i+c)%n,如果已经被选过则选下一个木有被选的点。问这些点能构成多少个直角三角形。
思路:直角三角形必须经过圆心。所以n为奇数必然无解。
否则先求出这m个点。每次求完后标记下,并用并查集加速。
code:
#line 7 "RightTriangle.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int fa[];
bool vis[]; class RightTriangle
{
public:
int find(int k){
return !vis[k] ? k : fa[k] = find(fa[k]);
}
long long triangleCount(int n, int m, long long a, long long b, long long c)
{
if (n & ) return ;
memset(vis, , sizeof(vis));
for (int i = ; i < n; ++i) fa[i] = (i + ) % n;
for (int i = ; i < m; ++i)
vis[find((a * i * i + b*i +c) % n)] = true;
long long ans = ;
for (int i = ; i < n / ; ++i)
if (vis[i] && vis[i + n / ]) ++ ans;
return ans * (m - );
}
};
SRM473的更多相关文章
随机推荐
- Minimum number of steps 805D
http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...
- 转录本组装软件StringTie的使用说明
转录本组装软件StringTie的使用说明 StringTie 转录本组装软件StringTie的使用说明 转录组分析流程 HISTA + StringTie 组合.其Protocol 发表在Natu ...
- jsonp,ajax,json问题
JSONP技术 JSONP是解决跨域问题的一种常见方式 跨域问题,因为浏览器有同源策略,所以当不同域间进行数据交互的时候就会出现跨域问题 同源策略:只有在同协议.同域名.同端口的情况下才能进去数据交互 ...
- java正则表达式(字符串)
参考:http://blog.csdn.net/kdnuggets/article/details/2526588 补充: ?号的使用: ^/branch/([a-z]+[/]?)$ 可以匹配 /b ...
- java基本例子
文件结构 D:\jp\jarDemo\IAmMainClass.java import iAmPackage.*; public class IAmMainClass { public static ...
- maven打包证(支付)书问题
要将证书文件后缀添加到resource文件夹内范围,添加打包文件后缀(include) 添加maven配置: <resources> <resource> <direct ...
- 【Erlang】源码安装
Erlang介绍 Erlang(['ə:læŋ])是一种通用的面向并发的编程语言,它由瑞典电信设备制造商爱立信所辖的CS-Lab开发,目的是创造一种可以应对大规模并发活动的编程语言和运行环境. Erl ...
- 在python中while
一.While循环 1.while循环格式 while 条件 : while循环体 当条件为Ture时,执行循环体,直到条件是假,停止循环. count = 1 # count 计数 一般用于计数 w ...
- 【转】Linux 如何通过命令仅获取IP地址
一同事的朋友正在参加笔试,遇到这么一个问题让他帮忙解决,结果同事又找到我帮他搞定.真是感慨:通讯发达在某些方面来说,真不知是不是好事啊!题目大致如下所示,一般我们使用ifconfig查看网卡信息,请问 ...
- Mysql导入excel数据,解决某些特殊字符乱码问题
问题 做项目需要从excel表格导入到mysql的数据库表中,excel表格中的“规格”字段的“×”符号导入数据库表中,会出现部分数据的“×”这个符号会乱码,成“?”的形式. 解决方法 打开excel ...