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的更多相关文章
随机推荐
- iOS.mach_absolute_time
1. Technical Q&A QA1398 Mach Absolute Time Units https://developer.apple.com/library/mac/qa/qa13 ...
- 洛谷1993 小K的农场
原题链接 裸的差分约束. \(X_a-X_b\geqslant C\) \(X_a-X_b\leqslant C\Rightarrow X_b-X_a\geqslant -C\) \(X_a-X_b\ ...
- Unix和Windows文件格式转化
可能的原因有: 1)执行权限的问题 解决方法: chmod +x ***.py 2)python版本的问题 解决方法:在执行时或者在py文件中选择好对应的Python的版本 3)python文件格式的 ...
- PropertyPlaceholderConfigurer
PropertyPlaceholderConfigurer Spirng在生命周期里关于Bean的处理大概可以分为下面几步: 加载 Bean 定义(从xml或者从@Import等) 处理 BeanFa ...
- 爬虫初窥day1:urllib
模拟“豆瓣”网站的用户登录 # coding:utf-8 import urllib url = 'https://www.douban.com/' data = urllib.parse.urlen ...
- SSRF-php初探
0x00 前言 1) SSRF的概念很好理解,请自行百度. 2) JAVA/PHP/PYTHON都存在SSRF漏洞(至于其他语言的情况,了解粗浅尚不得知). 3) SSRF的利用方式 ...
- git版本控制工具的使用(3)
git remote查看远程库的信息get remote -v可以更详细,查看推送和抓取权限 git push origin master把本地的master提交到远程的库对应的主分支 gt push ...
- python console 设立快捷键 学习源码 用到英语
arbitrary---随意 iterable----迭代 invalid syntax -----无效的语法 subscriptable ----可索引访问的
- PHP array
一.数组操作的基本函数 数组的键名和值 array_values($arr);获得数组的值 array_keys($arr);获得数组的键名 array_flip($arr);数组中的值与键名互换(如 ...
- idea下启动tomcat时,打印的日志中文乱码
idea2018.2+tomcat8+java8+win10 异常:将编码方式全都修改为UTF-8后,且tomcat的VM启动参数中配置了:-Dfile.encoding=UTF-8.导致控制台日志打 ...