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)是 ...
随机推荐
- 在MAC下使用Robotframework+Selenium2【第一枪】robotframework安装步骤
最近使用苹果的MAC Pro本本,感受着苹果系统的新鲜,确实让我手忙脚乱一阵,毕竟使用windows系统太长时间了,刚开始用MAC Pro确实感觉别扭,用了一段,发现MAC系统还不错,好了,转入正题. ...
- 安装Mysql community server遇到计算机中丢失msvcr120.dll
一.下载community server版本 Mysql community server版本:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7 ...
- leetcode 【 Plus One 】python 实现
题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...
- plsql 编程基础
分支 declare --声明变量 a ); b ); c ); begin --开始 a := '小明'; dbms_output.put_line(a); b :; c :; if b > ...
- Python 操作 SQLite 数据库
写在之前 SQLite 是一个小型的关系型数据库,它最大的特点在于不需要单独的服务.零配置.我们在之前讲过的两个数据库,不管是 MySQL 还是 MongoDB,都需要我们安装.安装之后,然后运行起来 ...
- .Net MVC删除图片
还在学校,菜鸟级别,接触到的只是 /// <summary> /// 根据imageID删除图片 /// </summary> /// <returns>< ...
- windows服务-监视文件
配置一个xml其中有是否开启监视.监视时间.监视路径. FileSystemWatcher watcherName = new FileSystemWatcher(); watcherName.Inc ...
- 洛谷P2056 采花
P2056 采花 52通过 99提交 题目提供者shengmingkexue 标签云端↑ 难度省选/NOI- 时空限制1s / 128MB 提交 讨论 题解 最新讨论更多讨论 求助莫队为什么被卡 ...
- PowerDesigner数据模型(CDM—PDM—SQL脚本的转换流程)
原文地址:PowerDesigner数据模型(CDM-PDM-SQL脚本的转换流程)作者:zzenglish 有图片的参考http://blog.sina.com.cn/s/blog_64742675 ...
- [网络流24题] COGS 搭配飞行员
14. [网络流24题] 搭配飞行员 ★★☆ 输入文件:flyer.in 输出文件:flyer.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 飞行大队 ...