TC 668 #DIV2
来源:互联网 发布:平板电脑软件助手 编辑:程序博客网 时间:2024/05/29 09:42
250 points:
You are going to send a message to your friend. The message is given as the stringmessage. To confuse potential eavesdroppers, you are going to scramble the message.Scrambling of a message is performed using the vector <int> key. If a letter is at the (0-based) position i in the original message, it will appear at the positionkey[i] in the scrambled message. (The constraints given below guarantee that this process will produce a valid scrambled message.)
To make the encryption even more confusing, you are going to repeat the above processK times in a row. Givenmessage, key, and the intK, find and return the final encrypted message.分析:直接暴力
/*"abcde"{4, 3, 2, 1, 0}1Returns: "edcba"*/#include <iostream>#include <fstream>#include <cstring>#include <climits>#include <cmath>#include <queue>#include <ctime>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <algorithm>typedef long long LL;using namespace std;class VerySecureEncryption {public: string encrypt( string message, vector <int> key, int K ) { int sz=key.size(); string ans; for(int i=0;i<K;i++) { for(int j=0;j<sz;j++) ans[key[j]]=message[j]; for(int j=0;j<sz;j++) message[j]=ans[j]; } return message; }};// Powered by FileEdit// Powered by moj 4.12 [modified TZTester]// Powered by CodeProcessor
600 points:
It's a bird! It's a plane! No, it's a square in a plane! Wait, is it really a square?
There are four distinct points in the plane. You are given their coordinates in the vector <int>sx andy: for each i between 0 and 3, inclusive, there is a point at (x[i],y[i]).
Return "It's a square" (quotes for clarity) if the four points are the vertices of a square. Otherwise, return "Not a square".分析:判断是不是正方形
上次BC看到一个较好的方法:连上对角两条边共六条边排序,前4条边相等,后两条边相等前是前4条边平方的2倍。
/*{0, 0, 2, 2}{0, 2, 0, 2}Returns: "It's a square"*/#include <iostream>#include <fstream>#include <cstring>#include <climits>#include <cmath>#include <queue>#include <ctime>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <algorithm>typedef long long LL;using namespace std;double A[10];double dis(int x1,int y1,int x2,int y2){ double x=x1-x2; double y=y1-y2; return x*x+y*y;}class IsItASquare {public: string isSquare( vector <int> x, vector <int> y ) { int tot=0; for(int i=0;i<4;i++) for(int j=i+1;j<4;j++) A[tot++]=dis(x[i],y[i],x[j],y[j]); sort(A,A+tot); int flag; if(A[0]==A[1]&&A[1]==A[2]&&A[2]==A[3]&&A[4]==A[5]&&A[5]==2*A[3]) flag=1; else flag=0; return flag?"It's a square":"Not a square"; }};// Powered by FileEdit// Powered by moj 4.12 [modified TZTester]// Powered by CodeProcessor
1000 points:
One day, Bob the Coder was wondering whether abstract programming problems can have applications in practice. The next day, he was selected to be on a quiz show. He will win one million dollars if he answers the following question:
Given a vector <int> A with N elements and an int K, count the number of tuples (p, q, r) such that 0 <= p < q < r < N andA[p] *A[q] * A[r] is divisible byK.
Please compute and return the answer to Bob's question.分析:让你找三元组满足A[P]*A[Q]*A[R]整除K其实我们可以暴力前两个的乘积找到第三个
做下预处理
/*-A will contain between 3 and 2,000 elements, inclusive.K will be between 1 and 1,000,000, inclusive.Each element of A will be between 1 and 100,000,000, inclusive.{4, 5, 2, 25}100Returns: 2*/#include <iostream>#include <fstream>#include <cstring>#include <climits>#include <cmath>#include <queue>#include <ctime>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <algorithm>typedef long long LL;using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )LL sum[1010][2010];int b[2010];LL a[2020];class AnArray {public: int solveProblem( vector <int> A, int K ) { CLEAR(sum,0); int tot=0; int n=A.size(); REP(i,n) a[i+1]=1LL*A[i]; for(int i=1;i<=K;i++) { if(K%i) continue; b[tot]=i; for(int j=1;j<=n;j++) { if(a[j]%i==0) sum[tot][j]=1; sum[tot][j]+=sum[tot][j-1]; } tot++; } int ans=0; for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { LL x=a[i]*a[j]; int t=K/__gcd(1LL*K,x); int pos=lower_bound(b,b+tot,t)-b; ans+=sum[pos][n]-sum[pos][j]; } } return ans; }};// Powered by FileEdit// Powered by moj 4.12 [modified TZTester]// Powered by CodeProcessor
0 0
- TC 668 #DIV2
- TC SRM 152 DIV2
- TC SRM 540 DIV2
- TC SRM 548 DIV2
- TC SRM 400 DIV2
- TC SRM 549 DIV2
- tc-551-div2
- TC SRM 552 DIV2
- tc-552-div2
- TC SRM 553 DIV2
- TC 555 div2
- TC SRM 571 div2
- TC SRM580 DIV2
- TC SRM599 div2 p950
- TC SRM573 div2 p1000
- TC SRM601 div2 p1000
- TC SRM 604 div2
- tc srm623 div2
- 随机函数Random()生成验证码
- Rectangle Area 两个矩形的面积
- 长沙河西网劲爆上线 引领长沙河西人网络新生活
- Web服务器的常见端口
- IOS9 未受信任的企业级开发者 没有信任按钮 解决
- TC 668 #DIV2
- windows下socket编程:区分shutdown()及closesocket()
- Contains Duplicate 重复数的判断
- NameNode 接收请求
- 正则表达式的学习及示例
- Mark
- IOS动画相关知识
- 扑克牌顺子
- C all