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的更多相关文章
随机推荐
- BZOJ1001或洛谷4001 [BJOI2006]狼抓兔子
BZOJ原题链接 洛谷原题链接 显然就是求最小割. 而对于一个平面图有结论,最大流=最小割=对偶图最短路. 所以这题可用最大流或是转换为对偶图求最短路,这里我是用的对偶图. 虽然理论上按上界算,这题\ ...
- CH6901 骑士放置
原题链接 和棋盘覆盖(题解)差不多.. 同样对格子染色,显然日字的对角格子是不同色,直接在对应节点连边,然后就是二分图最大独立集问题. #include<cstdio> #include& ...
- String... to 可变参数的使用
public class testMail { public static void fun(int... x) { for(int i = 0;i < x.length;i++) { Syst ...
- wepy中页面的跳转
1.在pages中创建好页面之后,需要在app.wpy中的config中配置好页面路由:2.如果跳转的按钮在page页面中 this.$navigate({url:"content" ...
- keepalived配虚拟ip(vip)的作用
keepalived是以VRRP协议为实现基础的,VRRP全称Virtual Router Redundancy Protocol,即虚拟路由冗余协议. 虚拟路由冗余协议,可以认为是实现路由器高可用的 ...
- ajax之Content-Type决定form-data方式提交还是request-payloud等
1.post请求的Content-Type为application/x-www-form-urlencoded,参数是在请求体中,即上面请求中的Form Data. 在servlet中,可以通过req ...
- DNA计算机及DNA存储
傅里叶变换到量子水平,可编程元素到原子分子核能,都可以极大的改变有机体(高级有机体都是有寿命的,例如人类),如果可以出现机械体,核能提供能量:并结合类似高级生物大脑的有机体大脑,不断学习进化,甚至优化 ...
- 【RabbitMQ】 RabbitMQ安装
MQ全称为Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们.消息传递指的是程序之间 ...
- 20155312 2016-2017-2 《Java程序设计》第五周学习总结
20155312 2016-2017-2 <Java程序设计>第五周学习总结 课堂笔记 十个基本类型 命令:ascii打印ascii值, od -tx1 Test.java用十六进制查看代 ...
- Web中的四大作用域对象
request:请求对象 类型:HttpServletRequest session:表示一次会话,可以处理一个用户多个页面之间的请求 application:标识web应用上下文,类型:Servle ...