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

  1. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  2. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  3. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  4. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

  5. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  6. Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索

    最近连续三次TC爆零了,,,我的心好痛. 不知怎么想的,这题把题意理解成,第一次选择j,第二次选择i后,只能从1~i-1.i+1~j找,其实还可以从j+1~n中找,只要没有被选中过就行... [题意] ...

  7. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  8. 【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 ...

  9. 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)是 ...

随机推荐

  1. CSS需要注意的问题1(转生活因拼搏而精彩的网易博客)

      1.检查HTML元素(如:<ul>.<div>).属性(如:class=”")是否有拼写错误.是否忘记结束标记(如:<br />) 因为Xhtml 语 ...

  2. Kinect安装

    在连接kinect机器前,需要先安装两个软件,而在安装这两个软件前需要有vs2010(专业版本和快速版),因为需要包含.net framework 4.0 kinect sdk http://www. ...

  3. OpenCV学习笔记(六) 滤波器 形态学操作(腐蚀、膨胀等)

    转自:OpenCV 教程 另附:计算机视觉:算法与应用(2012),Learning OpenCV(2009) 平滑图像:滤波器 平滑 也称 模糊, 是一项简单且使用频率很高的图像处理方法.平滑处理的 ...

  4. 自定义RadioGrop,支持添加包裹着的RadioButton

    控件类: package com.chinaCEB.cebView; import android.annotation.TargetApi; import android.content.Conte ...

  5. Redis实现之字符串

    简单动态字符串 Redis中的字符串并不是传统的C语言字符串(即字符数组,以下简称C字符串),而是自己构建了一种简单动态字符串(simple dynamic string,SDS),并将SDS作为Re ...

  6. C#+VisionPro连接相机获取图像的两种方式

    两种比较常用的方式. C#直接连接相机获取图像(GIGE) 在获取图像前,需要先创建一个相机对象,再使用这个相机对象的Acquire方法拍摄照片. ICogAcqFifo macqfifo;//定义相 ...

  7. Maven web项目的项目如何创建

    1.eclipse--创建maven项目--选择打包方式为war 2.此时项目还缺少一些东西,比如web-inf,web.xml配置文件之类的 3.项目右键-properties-project fa ...

  8. Python + Selenium 自动化环境搭建过程

    1.  所需组建 1.1  Selenium for python 1.2  Python 1.3  Notepad++ 作为刚初学者,这里不建议使用Python IDE工具,选择一个功能强大的记事本 ...

  9. Python-S9-Day123——爬虫两示例

    01 今日内容回顾 02 内容回顾和补充:面向对象约束 03 爬虫之抽屉新热榜 04 爬虫之抽屉自动登录(一) 05 爬虫之抽屉自动登录(二) 06 爬虫之登录github(一) 07 爬虫之登录gi ...

  10. PAT乙级 1001(C)+1054(Java)

    准备一天两道题,就这样吧,先从水题开始. 1001.点击查看 分析:看懂题就应该写出来了,注意边界与0情况的处理. #include<stdio.h> #include<math.h ...