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 ...
随机推荐
- centos6.5 squid安装
squid作用 1正向代理 标准的代理缓冲服务器,须在每一个内部主机的浏览器上明确指明代理服务器的IP地址和端口号. 透明代理缓冲服务器,代理操作对客户端的浏览器是透明的(即不需指明代理服务器的IP和 ...
- JWT认证原理及使用
一.JWT原理: 参考文章:https://www.jianshu.com/p/180a870a308a 1.传统的登录方式: 浏览器输入用户名密码,服务端校验通过,根据用户信息生成一个token,将 ...
- vue项目打包问题
使用vue-cli脚手架构建vue项目 vue init webpack project npm run build 打包时出现 Tip: built files are meant to be se ...
- python第三章:循环语句--小白博客
Python条件语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. 可以通过下图来简单了解条件语句的执行过程: Python程序语言指定任何非0和非 ...
- Bad Hair Day POJ - 3250 (单调栈入门题)
Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-cons ...
- 用友云开放平台之API网关
本文介绍选择API网关应考虑的几方面内容,API网关在微服务框架中的作用,API网关如何选型,用友云开放平台的API网关可以做什么. 随着互联网的快速发展,当前已步入移动互联.物联网时代.企业内部系统 ...
- B-Tree 和 B+Tree
B-Tree和B+Tree 本文来自 Hubery_James 的CSDN 博客 ,全文地址请点击:原文地址-干货满满 B+树索引是B+树在数据库中的一种实现,是最常见也是数据库中使用最为频繁的一种索 ...
- html总结:表格中的文字居中
<style> table { text-align:center; } </style>
- MySQL的视图总结
使用下面格式创建视图: create or replace view viewName as select ..... from ...... where .... 删除视图: drop view v ...
- 【学习总结】C-翁恺老师-入门-第0周<程序设计与C>
[学习总结]C-翁恺老师-入门-总 1-首先按视频说的下载编辑器 <DevC++> 并一路默认设置: 安装包下载链接 (我有vc6.0不过预感告诉我老师要用类似CS50里那种命令行编辑器? ...