Codeforces Round #454 Div. 1
B:考虑2*m怎么构造。因为要求相邻的数不能再相邻,容易想到黑白染色之类的东西,考虑染个色然后大概把黑点扔一边白点扔一边。显然m<=3时无解。对m>4,m为偶数时,如1 2 3 4 5 6 7 8 9 10 11 12,就变换成1 3 5 2 4 6 8 10 12 7 9 11;m为奇数时,如1 2 3 4 5 6 7 8 9 10,就变换成1 3 5 2 4 7 9 6 8 10(当然奇偶没有本质区别)。非常开心的发现我们只要把2*m的方案往下复制就可以得到n*m的方案了。n>3和m>3没有本质区别。上面的构造对m=4不适用,直接把样例搬过来就好,但要判n为奇数的情况,最后一行特殊处理。最后特判一下n=m=3和n=m=1,随便构造一组即可。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[2][N],b[2][N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("c.in","r",stdin);
freopen("c.out","w",stdout);
#endif
cin>>n>>m;
if (n==1&&m==1) {cout<<"YES"<<endl;cout<<"1";return 0;}
if (n==3&&m==3)
{
cout<<"YES"<<endl;
cout<<"6 1 8"<<endl;
cout<<"7 5 3"<<endl;
cout<<"2 9 4"<<endl;
return 0;
}
if (n<=3&&m<=3) {cout<<"NO";return 0;}
cout<<"YES"<<endl;
if (m>3)
{
for (int i=1;i<=m;i++) a[0][i]=i,a[1][i]=i+m;
if (m>4)
for (int i=1;i<=m;i++)
{
if (i<=(m+1>>1)) b[0][i]=a[0][i*2-1];else b[0][i]=a[0][(i-(m+1>>1))<<1];
if (i<=(m>>1)) b[1][i]=a[1][i*2];else b[1][i]=a[1][(i-(m>>1))*2-1];
}
else
{
b[0][1]=a[1][1];b[0][2]=a[0][4];b[0][3]=a[1][3];b[0][4]=a[0][2];
b[1][1]=a[0][3];b[1][2]=a[1][2];b[1][3]=a[0][1];b[1][4]=a[1][4];
}
for (int i=0;i<n-(m==4&&(n&1));i++)
{
for (int j=1;j<=m;j++)
printf("%d ",b[i&1][j]+(i-(i&1))*m);
printf("\n");
}
if (m==4&&(n&1)) cout<<n*m-2<<' '<<n*m<<' '<<n*m-3<<' '<<n*m-1<<endl;
}
else
{
swap(n,m);
for (int i=1;i<=m;i++) a[0][i]=(i-1)*n+1,a[1][i]=(i-1)*n+2;
if (m>4)
for (int i=1;i<=m;i++)
{
if (i<=(m+1>>1)) b[0][i]=a[0][i*2-1];else b[0][i]=a[0][(i-(m+1>>1))<<1];
if (i<=(m>>1)) b[1][i]=a[1][i*2];else b[1][i]=a[1][(i-(m>>1))*2-1];
}
else
{
b[0][1]=a[1][1];b[0][2]=a[0][4];b[0][3]=a[1][3];b[0][4]=a[0][2];
b[1][1]=a[0][3];b[1][2]=a[1][2];b[1][3]=a[0][1];b[1][4]=a[1][4];
}
swap(n,m);
for (int i=1;i<=n;i++)
{
for (int j=0;j<m-(n==4&&(m&1));j++)
printf("%d ",b[j&1][i]+j-(j&1));
if (n==4&&(m&1))
{
if (i==1) cout<<2*m;
if (i==2) cout<<4*m;
if (i==3) cout<<1*m;
if (i==4) cout<<3*m;
}
printf("\n");
}
}
return 0;
//NOTICE LONG LONG!!!!!
}
C:冷静一下可以发现交换操作顺序对结果并没有影响,于是暴力枚举对哪个点集操作即可。但枚举完暴力验证可能不能做到很优美的复杂度。注意到最后一步操作的点一定是与所有点相连的,于是暴力dfs过程中压位记录每个点与其他点是否直接相连,操作的影响可以O(n)更新,即可做到O(2n·n)。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 22
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N][N],f[N],size[1<<N],LG2[1<<N],ans,End;
bool flag[1<<N];
void dfs(int i,int *f)
{
flag[i]=1;
for (int j=0;j<n;j++)
if (!flag[i|(1<<j)])
{
int g[N];
for (int x=0;x<n;x++) g[x]=f[x];
for (int x=0;x<n;x++)
if (g[j]&(1<<x)) f[x]|=g[j];
dfs(i|(1<<j),f);
for (int x=0;x<n;x++) f[x]=g[x];
}
for (int j=0;j<n;j++)
if (f[j]==(1<<n)-1&&size[ans]>size[i]) ans=i,End=j;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("c.in","r",stdin);
freopen("c.out","w",stdout);
#endif
n=read(),m=read();if (m==n*(n-1)/2) {cout<<0;return 0;}
while (m--)
{
int x=read()-1,y=read()-1;
a[x][y]=a[y][x]=1;
}
for (int i=1;i<(1<<n);i++) size[i]=size[i^(i&-i)]+1,LG2[i]=size[i]==1?LG2[i>>1]+1:0;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (a[i][j]||i==j) f[i]|=1<<j;
ans=(1<<n)-1;
dfs(0,f);
cout<<size[ans]+1<<endl;
while (ans) cout<<LG2[ans&-ans]<<' ',ans^=ans&-ans;
cout<<End+1;
return 0;
//NOTICE LONG LONG!!!!!
}
D:经典trick?恶心至极的就是判扩展欧拉定理要不要+φ(p),写的乱七八糟不知道是啥。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cassert>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,p[70],a[N],pre[N],pos[N],cnt,q;
int ksm(int a,int k,int P)
{
int s=1;
for (;k;k>>=1,a=1ll*a*a%P) if (k&1) s=1ll*s*a%P;
return s;
}
ll KSM(int a,ll k)
{
ll s=1;if (k>32) return 2000000000;
for (int i=1;i<=k;i++)
{
s*=a;
if (s>=2000000000) break;
}
return s;
}
ll get(int l,int r)
{
ll s=1;
for (int i=pre[r];i>=l;i=pre[i-1])
{
s=KSM(a[i],s);
if (s>=2000000000) break;
}
return s;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("c.in","r",stdin);
freopen("c.out","w",stdout);
#endif
n=read(),p[0]=read();
m=0;
while (p[m]>1)
{
m++;int x=p[m]=p[m-1];
for (int i=2;i*i<=x;i++)
if (x%i==0){p[m]/=i;p[m]*=i-1;while (x%i==0) x/=i;}
if (x>1) p[m]/=x,p[m]*=x-1;
}
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) if (a[i]==1) pos[++cnt]=i,pre[i]=pre[i-1];else pre[i]=i;
pos[++cnt]=n+1;
q=read();
while (q--)
{
int l=read(),r=read(),ans=1;
int u=*lower_bound(pos+1,pos+cnt+1,l);
ll t=get(min(min(r,l+m),u-1)+1,r);if (u<=min(r,l+m)) t=1;
for (int i=min(min(r,l+m),u-1);i>=l;i--)
{
ans=ksm(a[i],ans,p[i-l]);t=KSM(a[i],t);
if (i>l&&t>=p[i-l]) ans+=p[i-l];
}
printf("%d\n",ans%p[0]);
}
return 0;
//NOTICE LONG LONG!!!!!
}
Codeforces Round #454 Div. 1的更多相关文章
- Codeforces Round #454 Div. 1 [ 906A A. Shockers ] [ 906B B. Seating of Students ] [ 906C C. Party ]
PROBLEM A. Shockers 题 http://codeforces.com/contest/906/problem/A 906A 907C 解 水题,按照题意模拟一下就行了 如果是 ‘ ! ...
- Codeforces Round #454 (Div. 1) CodeForces 906D Power Tower (欧拉降幂)
题目链接:http://codeforces.com/contest/906/problem/D 题目大意:给定n个整数w[1],w[2],……,w[n],和一个数m,然后有q个询问,每个询问给出一个 ...
- Codeforces Round #454 Div. 2 A B C (暂时)
A. Masha and bears 题意 人的体积为\(V\),车的大小为\(size\),人能钻进车的条件是\(V\leq size\),人对车满意的条件是\(2V\geq size\). 现知道 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
随机推荐
- 给大家推荐8个SpringBoot精选项目
前言 2017年,曾在自己的博客中写下这样一段话:有一种力量无人能抵挡,它永不言败生来倔强.有一种理想照亮了迷茫,在那写满荣耀的地方. 如今2018年已过大半,虽然没有大理想抱负,但是却有自己的小计划 ...
- ThinkPHP+JQuery实现文件的异步上传
前端代码 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...
- .net core实践系列之短信服务-架构设计
前言 上篇<.net core实践系列之短信服务-为什么选择.net core(开篇)>简单的介绍了(水了一篇).net core.这次针对短信服务的架构设计和技术栈的简析. 源码地址:h ...
- js、jquery实现放大镜效果
在一些电商网站的商品详情页面,都会有放大镜效果,实现起来并不是很困难,今天用了两个小时,写了一个放大镜效果的实例,来分享给大家! 实现的效果大概是这个样子的 预览 先来看一下效果吧,点击下面的链接预览 ...
- Flask的蓝图和红图
1.蓝图 对于简单的项目来说,比如项目就只有一个user模块,我们可以都将视图函数定义在一个文件里面,不需要用到蓝图. 但是如果我们的项目有多个模块,如下有v1模块,v2模块.....等,那么如果我们 ...
- mongoDB 安装和配置环境变量,超详细版本
下载mongoDB进行安装:https://www.mongodb.com/ 到Community Se ...
- tailf、tail -f、tail -F三者区别(转)
tail -f 等同于--follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止 tail -F 等同于--follow=name --retry,根 ...
- 三、Object 对象常用操作方法
Object 构造方法 一.asign vs 扩展运算符 ... 1.共同点:都是浅拷贝 2.开发推荐 扩展运算符... let obj={ name: 'Tom', age: 18 }; let o ...
- 解读event.returnValue和return false
前言 首先我们要清楚returnValue是IE的一个属性,如果设置了该属性,它的值比事件句柄的返回值优先级要高,把它的值设置为false,可以取消发生事件源元素的默认动作:return false就 ...
- package-lock.json和package.json的作用
转自:https://www.cnblogs.com/cangqinglang/p/8336754.html package-lock.json的作用就是锁定安装依赖时包的版本,并且需要上传到git, ...