C. Cyclic Permutations

思路:全排列减去单峰排列即为答案。

单峰排列即:峰左边下标的左边没有比它大的,峰右边的下标的右边没有比它大的。

单峰排列个数: 2 n − 1 2^{n-1} 2n−1,除 n n n外每个数可在左侧或右侧。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
ll ksm(ll a,ll n){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;
}
int main(){int n;scanf("%d",&n);ll x=1;for(int i=1;i<=n;i++) x=x*i%mod;printf("%lld\n",((x-ksm(2,n-1))%mod+mod)%mod);return 0;
}

D. 505

思路:结论:

1. n > 3 1.n>3 1.n>3无解,因为 4 × 4 4\times 4 4×4矩阵的 4 4 4个 2 × 2 2\times 2 2×2矩阵和不满足。

2. n = 1 , a n s = 0 2.n=1,ans=0 2.n=1,ans=0

所以只需考虑 n = 2 , 3 n=2,3 n=2,3的情况,暴力枚举第一列第二列,第二列和第三列的答案情况,取最小值即可。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
#define IOS ios::sync_with_stdio(false),cin.tie(0)
int main(){IOS;int n,m;cin>>n>>m;vector<vector<int> >a(n,vector<int>(m));string s;for(int i=0;i<n;i++){cin>>s;for(int j=0;j<m;j++) a[i][j]=s[j]-'0'; }if(n>3) return cout<<-1<<endl,0;if(n==1) return cout<<0<<endl,0;int ans=n*m;for(int x=0;x<2;x++)for(int y=0;y<2;y++){int tmp=0;for(int j=0;j<m;j++){int s1=(a[0][j]+a[1][j])%2,c=(x+j)%2;//第一列和第二列. if(s1!=c) tmp++;if(n==3){int s2=(a[1][j]+a[2][j])%2,d=(y+j)%2;//第二列和第三列 if(s2!=d&&s1==c) tmp++;//若两个都需要改,则只需改中间的格子,上面已经加过一次. }}if(ans>tmp) ans=tmp;}cout<<ans<<endl;;return 0;
}

Codeforces Round #663 (Div. 2) (CD)相关推荐

  1. Codeforces Round #663 (Div. 2)

    2020/8/9晚上断网了,本来不想打就顺便看看题目,发现能做几个,然后就交了.(做完1.2两题才敢交)最终做了3个题tcl. A - Suborrays 脑筋急转弯题目.位运算OR运算结果只会变大不 ...

  2. Codeforces Round #663 (Div. 2) A-D

    A:SuborraysA: SuborraysA:Suborrays 思路: x∣y>=max(x,y)x|y>=max(x,y)x∣y>=max(x,y),线性输出即可. 参考代码 ...

  3. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  4. Codeforces Round #706 (Div. 2)-A. Split it!-题解

    目录 Codeforces Round #706 (Div. 2)-A. Split it! Problem Description Input Output Sample Input Sample ...

  5. Codeforces Round #706 (Div. 2)-B. Max and Mex-题解

    目录 Codeforces Round #706 (Div. 2)-B. Max and Mex Problem Description Input Output Sample Input Sampl ...

  6. Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)

    题目链接:Codeforces Round #271 (Div. 2) C. Captain Marmot 题意:给4行数据,每行2个点.(x,y).(a,b).意思是(x,y)绕(a,b)逆时针旋转 ...

  7. Codeforces Round #704 (Div. 2)-A. Three swimmers-题解

    目录 Codeforces Round #704 (Div. 2)-A. Three swimmers Problem Description Input Output Sample Input Sa ...

  8. Codeforces Round #704 (Div. 2)-C. Maximum width-题解

    目录 Codeforces Round #704 (Div. 2)-C. Maximum width Problem Description Input Output Sample Input Sam ...

  9. Codeforces Round #704 (Div. 2)-B. Card Deck-题解

    目录 Codeforces Round #704 (Div. 2)-B. Card Deck Problem Description Input Output Sample Input Sample ...

最新文章

  1. html在线缓存视频,javascript – 如何为HTML视频添加缓冲
  2. sed线上经典案例之-同时替换多个字符串
  3. 坡道行驶电动小车_事发红绿灯路口!东莞一女子骑电动滑板车被撞致颅内出血…...
  4. 启明云端分享|ESP32-C3模块入门应用
  5. linux连接教程视频,[原创]linux视频教程之连接
  6. 算法题目——整数划分(HRBUST-2004)
  7. mysqldumper
  8. CNN和FCN的区别
  9. 【干货】前端工程与性能优化
  10. 分布式和微服务_太难了!阿里三面凉透~ Spring+高并发+算法+分布式微服务等等一个都没讲不清...
  11. Python 这么热,运维要不要追赶 Python 的热潮?
  12. 网络编程实验综合报告
  13. 安装 Office 2010 错误 error 1935和数据库以及安卓路线
  14. 国际象棋渲染测试软件,测试了五款软件八款游戏:AMD三代锐龙YES!但游戏英特尔略胜一筹...
  15. 微信公众号的黑色商业链揭秘
  16. Java 给PDF文件添加水印
  17. 【精美后台管理系统模版->UI界面欣赏】
  18. revit二次开发--异形柱翻模
  19. 查看oracle负载过大的原因,Oracle备份时系统负载过高导致ORA-3136错误和AIX系统的3D32B80D错误...
  20. git clone报错:could not read Username for ‘http://xxx.com‘: Device not configured

热门文章

  1. 试着用Eclipse M6
  2. 在excel内处理二进制和十六进制数据
  3. 产业分析:视频号发展白皮书
  4. Unity中模拟爆炸的力
  5. 魔方生活服务再战港股,长租公寓能否迎来春天?
  6. ZYNQ OCM地址分配和双核使用配置
  7. odbc jdbc mysql_JDBC和ODBC之间的区别
  8. 20190928多益网络前端笔试总结
  9. 华为明年即将推出2款5nm芯片,覆盖中高端,或将全面反超高通
  10. 百度快速收录神器 新站长SEO工具