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的更多相关文章

随机推荐

  1. nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator

    该问题是少了一个spring-tx-的jar包,把该包加入到buildpath中就行了. 参考链接:http://blog.csdn.net/Rongbo_J/article/details/4666 ...

  2. xml配置sql语句

  3. Spring MVC 数据绑定和表单标签库

    数据绑定是将用户输入绑定到领域模型的一种特性.作用是将 POJO 对象的属性值与表单组件的内容绑定. 数据绑定的好处: 1. 类型总是为 String 的 HTTP 请求参数,可用于填充不同类型的对象 ...

  4. Spring PropertyResolver 占位符解析(二)源码分析

    Spring PropertyResolver 占位符解析(二)源码分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ...

  5. Koko Eating Bananas LT875

    Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The g ...

  6. Sliding Window Maximum LT239

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  7. 利用PHP脚本辅助MySQL数据库管理4-两个库表结构差异比较

    <?php define('DATABASE1', 'coffeetest'); $dbi1 = new DbMysql; $dbi1->dbh = 'mysql://root:mysql ...

  8. canvas和图片互转

    原文:http://www.jb51.net/html5/160920.html 这么神奇么?先记录一下. 使用JavaScript将图片拷贝进画布 要想将图片放入画布里,我们使用canvas元素的d ...

  9. 如何使用GCC生成动态库和静态库

    根据链接时期的不同,库又有静态库和动态库之分.静态库是在链接阶段被链接的,所以生成的可执行文件就不受库的影响,即使库被删除,程序依然可以成功运行.而动态库是在程序执行的时候被链接的.程序执行完,库仍需 ...

  10. 25、UIView的setNeedsLayout, layoutIfNeeded 和 layoutSubviews 方法之间的关系解释

    layoutSubviews总结 ios layout机制相关方法 - (CGSize)sizeThatFits:(CGSize)size- (void)sizeToFit——————- - (voi ...