Topcoder SRM 668 DIV 2
VerySecureEncryption 模拟
题意:
给你个串message,然后一个置换key,输出置换K次后的结果。
题解:
直接模拟就好。
代码:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std; class VerySecureEncryption {
public:
string encrypt(string message, vector<int> key, int K) {
char res[][];
for (int i = ; i < message.length(); i++)res[][i] = message[i];
for (int i = ; i < K; i++)
for (int j = ; j < message.length(); j++)
res[i & ][key[j]] = res[(i + ) & ][j];
string r;
for (int i = ; i < message.length(); i++)
r = r + res[(K - ) & ][i];
return r;
}
};
IsItASquare 计算几何
题意:
给你平面上四个点,问你是否能够构成正方形
题解:
取三个点,看是否能够构成等腰直角三角形,然后再check一下最后一个点。
代码:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std; class Coordinate
{
public:
double xCoordinate;
double yCoordinate; Coordinate(double x = ,double y = )
{
this->xCoordinate = x;
this->yCoordinate = y;
} bool operator!=(Coordinate const &comp) const
{
return (this->xCoordinate != comp.xCoordinate ||
this->yCoordinate != comp.yCoordinate);
}
}; /**
* @explanation 判断是否为等腰直角三角形.
*/
bool Judge(Coordinate const x,Coordinate const y,Coordinate const z)
{
Coordinate *mVector = new Coordinate(x.xCoordinate - y.xCoordinate,
x.yCoordinate - y.yCoordinate);
Coordinate *nVector = new Coordinate(z.xCoordinate -
(x.xCoordinate + y.xCoordinate)/,
z.yCoordinate -
(x.yCoordinate + y.yCoordinate)/);
//判断是否为等腰三角形
bool result = ((mVector->xCoordinate * nVector->xCoordinate +
mVector->yCoordinate * nVector->yCoordinate) == ); //判断是否是直角三角形
if(result)
result = (mVector->xCoordinate * mVector->xCoordinate +
mVector->yCoordinate * mVector->yCoordinate)
== ((nVector->xCoordinate * nVector->xCoordinate +
nVector->yCoordinate * nVector->yCoordinate) * ); delete mVector;
delete nVector; return result;
} bool IsSquare(Coordinate *array,int length)
{
if(length != )
return false;
int a,b,c; if(Judge(array[],array[],array[]))
{
a = ;
b = ;
c = ;
}
else if(Judge(array[],array[],array[]))
{
a = ;
b = ;
c = ;
}
else if(Judge(array[],array[],array[]))
{
a = ;
b = ;
c = ;
}
else
return false; return (array[] != array[c] && Judge(array[a],array[b],array[]));
} class IsItASquare {
public:
string isSquare(vector <int> x, vector <int> y) {
Coordinate ar[];
for(int i=;i<;i++)ar[i].xCoordinate=x[i],ar[i].yCoordinate=y[i];
return IsSquare(ar,)?"It's a square":"Not a square";
}
};
AnArra 乱搞
题意:
给你个序列A,统计A[i]*A[j]*A[k]%K==0的个数,i<j<k
题解:
采用存一半搜一半的思想,预处理出每个因子有多少倍数。然后枚举A[i],A[j],令g=gcd(A[i]*A[j],K),t=K/g,那么问题就是有多少数是t的倍数,这个刚刚已经预处理好了。
代码:
#include<iostream>
#include<map>
#include<algorithm>
using namespace std; typedef long long ll; int ma[]; ll gcd(ll a,ll b) {
return b == ? a : gcd(b, a % b);
} class AnArray {
public:
int solveProblem(vector<int> A, int K) {
for (auto a:A) {
for (int i = ; i * i <= a; i++) {
if (a % i == ) {
ma[i]++;
int t = a / i;
if (i * i != a && t <= )ma[t]++;
}
}
}
ll res = ;
for (int i = ; i < A.size(); i++)
for (int j = ; j < A.size(); j++) {
if (i == j)continue;
ll tmp = ;
tmp = tmp * A[i] * A[j];
int g = gcd(tmp, K);
int t = K / g;
res = res + ma[K / g];
if (A[i] % t == )res--;
if (A[j] % t == )res--;
}
return res / ;
}
};
Topcoder SRM 668 DIV 2的更多相关文章
- TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E
传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...
- TopCoder SRM 667 Div.2题解
概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...
- [topcoder]SRM 646 DIV 2
第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...
- [topcoder]SRM 633 DIV 2
第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...
- TopCoder SRM 596 DIV 1 250
body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...
- Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索
最近连续三次TC爆零了,,,我的心好痛. 不知怎么想的,这题把题意理解成,第一次选择j,第二次选择i后,只能从1~i-1.i+1~j找,其实还可以从j+1~n中找,只要没有被选中过就行... [题意] ...
- Topcoder SRM 648 (div.2)
第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...
- 【topcoder SRM 702 DIV 2 250】TestTaking
Problem Statement Recently, Alice had to take a test. The test consisted of a sequence of true/false ...
- TopCoder SRM 639 Div.2 500 AliceGameEasy
题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数 解题思路: 首先判断n(n+1)/2 = (x+y)是 ...
随机推荐
- VMware之无法切换桥接网络
一.关闭正在运行的虚拟机 二.打开虚拟网络编辑器 三.还原默认设置 四.启动虚拟机即可正常使用桥接网络
- sql中保留一位小数的百分比字符串拼接,替换函数,换行符使用
select num ,cast(round(convert(float,isnull((a.Sum_Num-d.Sum_Num),0))/convert(float,c.Sum_Store_Num ...
- “帮你APP”团队冲刺7
1.整个项目预期的任务量 (任务量 = 所有工作的预期时间)和 目前已经花的时间 (所有记录的 ‘已经花费的时间’),还剩余的时间(所有工作的 ‘剩余时间’) : 所有工作的预期时间:88h 目前已经 ...
- imageX
imageX 编辑 ImageX 是一个命令行工具,原始设备制造商 (OEM) 和公司可以使用它来捕获.修改和应用基于文件的磁盘映像以进行快速部署.ImageX 可以使用 Windows 映像 (.w ...
- 对于xss等有关的html,url,unicode编码做的一个小总结。
参考:http://bobao.360.cn/learning/detail/292.html,算是对前部分作一个总结性的学习. 1<a href="%6a%61%76%61%73%6 ...
- CSU-2221 假装是区间众数(ST表模版题)
题目链接 题目 Description 给定一个非递减数列Ai,你只需要支持一个操作:求一段区间内出现最多的数字的出现次数. Input 第一行两个整数N,Q 接下来一行有N个整数,表示这个序列. 接 ...
- sqlserver 操作access数据库
exec sp_configure 'show advanced options',1 reconfigure exec sp_configure 'Ad Hoc Distributed Quer ...
- [笔记]《算法图解》第十章 K最近邻算法
K最近邻算法 简称KNN,计算与周边邻居的距离的算法,用于创建分类系统.机器学习等. 算法思路:首先特征化(量化) 然后在象限中选取目标点,然后通过目标点与其n个邻居的比较,得出目标的特征. 余弦相似 ...
- 用例UML图
用例图主要用来描述“用户.需求.系统功能单元”之间的关系.它展示了一个外部用户能够观察到的系统功能模型图. [用途]:帮助开发团队以一种可视化的方式理解系统的功能需求. 用例图中涉及的关系有:关联.泛 ...
- easyui 右键绑定事件
$(function(){ $('#hospitalTree').bind('contextmenu', function(e) { e.preventDefault(); ...