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)是 ...
随机推荐
- RCP 主题切换
第一步 编写css文件,放到项目目录下 第二步 添加切换主题扩展点 第三步 设置主题 public void switchTheme(String themeID) { Bu ...
- c++实验4
1. 车辆基本信息管理 #include <iostream> using namespace std; #include <string> #include "c ...
- KNN算法python实现小样例
K近邻算法概述优点:精度高.对异常数据不敏感.无数据输入假定缺点:计算复杂度高.空间复杂度高适用数据范围:数值型和标称型工作原理:存在一个样本数据集合,也称作训练样本集,并且样本集中每个数据都存在标签 ...
- Python 命令总结
本章内容 pip pip install -r requirement.py(里面写入需要安装的包的名字) pip install django==1.9 #需要安装那个版本 P ...
- 可实现一键分享到多个平台(微信,微博,qq空间,人人等)
友推是一款是面向移动应用的SDK分享组件,提供给开发者集成使用.通过友推,开发者可以轻松集成社会化分享功能,同时创建及管理推荐好友使用您应用的推荐奖励活动,用户推荐好友安装使用您的应用即可获得推荐奖励 ...
- Python+Selenium练习篇之21-如何截图并保存
本文介绍如何利用Selenium的方法进行截图,在测试过程中,是有必要截图,特别是遇到错误的时候进行截图.在selenium for python中主要有三个截图方法,我们挑选其中最常用的一种. ge ...
- 【转】MapReduce:默认Counter的含义
MapReduce Counter为提供我们一个窗口:观察MapReduce job运行期的各种细节数据.今年三月份期间,我曾经专注于MapReduce性能调优工作,是否优化的绝大多评估都是基于这些C ...
- python 删除重复文件 附源代码
啥也不说了,直接上源码 #! /usr/bin/env python #coding=utf-8 import os import md5 import time def getmd5( filena ...
- Selenium - WebDriver: Locating Elements
Selenium provides the following methods to locate elements in a page: find_element_by_id find_elemen ...
- java的图像界面
package test; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.even ...