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. D3DXCreateTexture

    HRESULT D3DXCreateTexture( __in LPDIRECT3DDEVICE9 pDevice, __in UINT Width, __in UINT Height, __in U ...

  2. Maya材质

    mental ray--Indirect Lighting(物理学太阳天空)      Final Gathering最终聚集   改变质量为production的,FG就是关闭需要重新打开 平行光, ...

  3. Kinect安装

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

  4. shell脚本杀掉指定进程下所有子进程(包括子进程的子进程)

    搜索了网上好像并没有杀掉指定进程下所有子进程(包括子进程的子进程)的脚本,自己琢磨写了一版,虽说比较简单,但希望分享大家,帮助需要的人 #!/bin/sh # 递归找到进程最底层子进程并杀除. mai ...

  5. Android 停止调试程序

    现在我知道怎么停掉debug的Android程序了,很简单,进入ddms界面,对着你的进程,kill.

  6. TCP/IP网络编程之优雅地断开套接字

    基于TCP套接字的半关闭 Linux的close函数和Windows的closesocket函数意味着完全断开连接,完全断开连接不仅指无法传输数据,而且也不能接收数据.因此,在某些情况下,通信一方调用 ...

  7. np.newaxis()用法

    这个是liaspace函数 这个是np.newaxis的用法,增加维度,写一个表示增加一维,两个表示增加2维2位置的:号是对a的取值范围,如果把np.newaxis作为第一个参数是对行增加维度,作为第 ...

  8. 继承Thread类使用多线程

    java实现多线程有两种方式,一种是继承Thread类,另外一种就是实现Runnable接口. 两种实现方法的优缺点: 使用Thread类实现多线程局限性就是不支持多继承,因为java是不支持类多继承 ...

  9. Event log c++ sample.

    1. Init regedit. bool InitLog( TCHAR *logName, TCHAR *sourceName, TCHAR *MessageDllName ) { // This ...

  10. 2017腾讯Web前端实习生招聘笔试题总结

    指针与引用的区别 考察margin塌陷 考察C++继承和~符号 考察TCP通讯过程 位码 三次握手 为什么不是两次握手 为什么不是四次握手 四次挥手 为什么要四次握手 TCP的状态 考察严格模式 进程 ...