Educational Codeforces Round 83 (Rated for Div. 2)A--C
地址:http://codeforces.com/contest/1312


题意:给出一个边数为n的等边多边形,问是否可以变成m的等边多边形。条件是同一个中心,共用原顶点。
解析:直接n%m==0即可,这样就是平分了。签到题没得说了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=1e4;
int pr[maxn];
int find(int x)
{
if(x!=pr[x])
return pr[x]=find(pr[x]);
return x;
}
void join(int x1,int x2)
{
int f1=find(x1),f2=find(x2);
if(f1!=f2)
{
pr[f1]=f2;
}
return ;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
if(n%m==)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}

题意:把给定数组任意排列,保证i<j时,j-a[j]!=i-a[i]。输出任意一组答案。
解析:sort一下从大到小排列即可。看数据的话,暴力也是可以的。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
int a[];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=;i<=n;i++)
cin>>a[i];
while()
{
int ok=;
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if((j-a[j])==(i-a[i]))
{
ok=;break;
}
}
if(ok)
break;
}
if(!ok)
break;
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if((j-a[j])==(i-a[i]))
{
swap(a[i],a[j]);
}
}
}
}
for(int i=;i<n;i++)
cout<<a[i]<<" ";
cout<<a[n]<<endl;
} }


题意:给你一个个数为n的数组a[],判断是否可以由相同大小的全0数组v[]变换而来。
变换规则:
1.在第i次操作时,你可以给数组v任意位置的值加上k^i
2.在第i次什么也不做。
解析:这其实就是一个进制的题。对于任意一个a【i】假设k进制对其有n位:a[i]= x0* k^0 +x1* k^1 +x2* k^2 +……+x(n-1)* k^n-1
而这个题对于k^i的i,是不断递增的,即每个i只能出现一次。所以我们只要知道每个k^i的系数,大于1,就是NO了。
举个例子:二进制,k=2
5 6
5的二进制表示为101,2为110,101
110 可以看出,2^2那里出现了两次,肯定不服题意了。
这里用vis[]来记录各个k^i的出现次数,记住vis是与实际转化的k进制数方向是相反的。vis[]+=a[i]%k,这个a[i]%k,就是系数,即次数。最后注意一下vis[]开的大些
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=;
const int maxn2=;
ll a[maxn];
int vis[maxn2];
int t;
int main()
{
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<n;i++)
scanf("%lld",&a[i]);
memset(vis,,sizeof(vis));
int ok=;
for(int i=;i<n;i++)
{
int tot=;
while(a[i])
{
tot++;
vis[tot]+=a[i]%k;
a[i]=a[i]/k;
if(vis[tot]>)
{
ok=;break;
}
}
if(ok)
break;
}
if(!ok)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}
Educational Codeforces Round 83 (Rated for Div. 2)A--C的更多相关文章
- Educational Codeforces Round 83 (Rated for Div. 2)
A. Two Regular Polygons 题意:给你一个 正n边形,问你能否以这个 n 的其中一些顶点组成一个 m边形, 思路 :如果 n % m == 0 ,就可 收获:边均分 B. Bogo ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
随机推荐
- numpy矩阵运算--矩阵乘法
1)元素对应相乘,使用 multiply 函数或 * 运算符来实现 a = np.array([2,2,2])b = np.array([3,3,3]) c1 = a*a c1 array([4, 4 ...
- Redis实现高并发分布式锁
分布式锁场景在分布式环境下多个操作需要以原子的方式执行首先启一个springboot项目,再引入redis依赖包: <!-- https://mvnrepository.com/artifa . ...
- JavaScript创建函数的方式
在JavaScript中,创建函数是比较常见的操作,但是JavaScript中怎么创建函数呢,有几种方式可以创建函数呢?在JavaScript一般有三种方式创建对象1.函数声明方式格式:functio ...
- mysql数据库-索引-长期维护
############### 索引介绍 ############## """ 1. 索引介绍 需求: 一般的应用系统,读写比例在10:1左右,而且插入操作和 ...
- uname|mv|tar -xzvf|
$ ls CAFE-4.2.1.tar.gz mcl-latest.tar.gz mysql-5.4.3-beta-linux-i686-glibc23.tar.gz.1 orthomclSoftwa ...
- Mr.Yu
在linux下搭建Git服务器 git服务器环境 服务器 CentOS7 + git(version 1.8.3.1)客户端 Windows10 + git(version 2.16.0.window ...
- org.apache.http.NoHttpResponseException
org.apache.http.NoHttpResponseException 异常: org.apache.http.NoHttpResponseException: The target serv ...
- [LC] 328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
- java基础归纳
目录 1.java的8种基本数据类型: 2.java的三大特性 3.[public.private.protected区别]-访问权限 4.重载与重写区别 5.Throwable类.Error与Exc ...
- Qt QString与string的转换
QString --> string QString.toStdString(); string --> QString QString::fromStdString(string);