Codeforces_803
A. 填k个1,使矩阵主对角线对称,相同情况选择上面1数量多的。
#include<bits/stdc++.h>
using namespace std; int n,k,a[][] = {}; int main()
{
ios::sync_with_stdio(false);
cin >> n >> k;
if(k > n*n)
{
cout << - << endl;
return ;
}
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++)
{
if(a[i][j]) continue;
if(k >= && i == j)
{
k--;
a[i][j] = ;
}
else if(k >= )
{
k -= ;
a[i][j] = ;
a[j][i] = ;
}
}
}
if(k != )
{
cout << - << endl;
return ;
}
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++) cout << a[i][j] << " ";
cout << endl;
}
return ;
}
B.两个方向各跑一次,更新最邻近的0位置就可以了。
#include<bits/stdc++.h>
using namespace std; int n,a[],l[],r[]; int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i];
int last = -1e9;
for(int i = ;i <= n;i++)
{
if(a[i] == ) last = i;
l[i] = i-last;
}
last = 1e9;
for(int i = n;i >= ;i--)
{
if(a[i] == ) last = i;
r[i] = last-i;
}
for(int i = ;i <= n;i++) cout << min(l[i],r[i]) << " ";
cout << endl;
return ;
}
C.因为和为n,所以可以是某个最小的初始小序列的某倍数为n,达到gcd最大,枚举n的每一个因子即可。
#include<bits/stdc++.h>
using namespace std; long long n,k; int main()
{
ios::sync_with_stdio(fals#include<bits/stdc++.h>
using namespace std; long long n,k; int main()
{
ios::sync_with_stdio(false);
cin >> n >> k;
if(log(n*) < log(k)+log(k+)-1e-)
{
cout << - << endl;
return ;
}
long long t = k*(k+)/,maxx = ;
for(long long i = ;i*i <= n;i++)
{
if(n%i) continue;
{
if(i*t <= n) maxx = max(maxx,i);
if(t <= i) maxx = max(maxx,n/i);
}
}
for(long long i = ;i < k;i++) cout << i*maxx << " ";
cout << n-maxx*k*(k-)/ << endl;
return ;
}
e);
cin >> n >> k;
if(log(n*) > log(k)+log(k+)-1e-)
{
cout << - << endl;
return ;
}
long long t = k*(k+)/,maxx = ;
for(long long i = ;i*i <= n;i++)
{
if(n%i) continue;
{
if(i*t <= n) maxx = max(maxx,i);
if(n/i*t <= n) maxx = max(maxx,n/i);
}
}
for(int i = ;i <= n;i++) cout << i*maxx << " ";
cout << n-maxx*k*(k-)/ << endl;
return ;
}
D.直接划分成每个最小单词的字符个数,然后二分答案。
#include<bits/stdc++.h>
using namespace std; int n,cnt = ,a[] = {};
string s; bool ok(int x)
{
int cntt = ,now = ;
for(int i = ;i <= cnt;i++)
{
if(a[i] > x) return ;
now += a[i];
if(now > x)
{
cntt++;
now = a[i];
}
}
if(now > ) cntt++;
if(cntt <= n) return ;
return ;
}
int main()
{
cin >> n;
getchar();
getline(cin,s);
for(int i = ;i < s.length();i++)
{
a[cnt]++;
if(s[i] == ' ' || s[i] == '-') cnt++;
}
int l = ,r = 1e6;
while(l < r)
{
int mid = (l+r)/;
if(ok(mid)) r = mid;
else l = mid+;
}
cout << l << endl;
return ;
}
E.dp[i][j]表示到i轮状态为j的可能,j可以用赢的量表示,因为会有负值,可以设置一个偏移量,因为要记录路径,直接把dp[i][j]用来记录上一状态,然后逆向输出路径就可以了。
#include<bits/stdc++.h>
using namespace std; int n,k,a[][];
string s;
int main()
{
ios::sync_with_stdio(false);
cin >> n >> k >> s;
memset(a,-,sizeof(a));
a[][n] = ;
for(int i = ;i < n;i++)
{
for(int j = n-k+;j <= n+k-;j++)
{
if(a[i][j] == -) continue;
if(s[i] == '?' || s[i] == 'W') a[i+][j+] = j;
if(s[i] == '?' || s[i] == 'L') a[i+][j-] = j;
if(s[i] == '?' || s[i] == 'D') a[i+][j] = j;
}
}
if(a[n][n-k] == - && a[n][n+k] == -)
{
cout << "NO" << endl;
return ;
}
int now = n-k;
if(a[n][n-k] == -) now = n+k;
for(int i = n;i >= ;i--)
{
if(a[i][now] == now-) s[i-] = 'W';
else if(a[i][now] == now+) s[i-] = 'L';
else s[i-] = 'D';
now = a[i][now];
}
cout << s << endl;
return ;
}
F.gcd为1的序列数较难求得,我们可以求gcd不为1的序列数,预处理统计每个数的约数,求得所有约数的个数,其中,k个数中的选择情况有2^k-1种,容斥原理求得答案。
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std; int n,cnt[] = {},ans[],two[]; int main()
{
ios::sync_with_stdio(false);
cin >> n;
while(n--)
{
int x;
cin >> x;
for(int i = ;i*i <= x;i++)
{
if(x%i == )
{
cnt[i]++;
if(i*i != x) cnt[x/i]++;
}
}
}
two[] = ;
for(int i = ;i <= ;i++) two[i] = two[i-]*%MOD;
for(int i = ;i <= ;i++) ans[i] = two[cnt[i]]-;
for(int i = ;i >= ;i--)
{
for(int j = i*;j <= ;j += i) ans[i] = (ans[i]-ans[j]+MOD)%MOD;
}
cout << ans[] << endl;
return ;
}
Codeforces_803的更多相关文章
随机推荐
- (httpd、php)2
(一)再说编译安装httpd2.4 新特性: 1:MPM(多处理模块)支持运行为DSO(动态共享,动态加载模式)机制,以模块形式按需加载,支持动态加载 2:event MPM生产环境可用 3:支持异步 ...
- WTM 3.1发布,完美支持.netcore 3.1
在过去的2019年,承蒙各位的厚爱,WTM从零开始一年的时间在GitHub上收获了将近1600星,nuget上的下载量累计超过10万. WTM所坚持的低码开发,快速实现的理念受到了越来越多.netco ...
- GXOI&GZOI
T1 与或和 2s&&512MB 简明题意:求一个矩阵的所有子序列的 \(and\)和 和\(or\)和: 子矩阵的\(and\)和就是所有值\(and\)起来:\(or\)类 ...
- 【转】Java 正则表达式详解
正则表达式30分钟入门教程 常用正则表达式 如果你曾经用过Perl或任何其他内建正则表达式支持的语言,你一定知道用正则表达式处理文本和匹配模式是多么简单. 如果你不熟悉这个术语,那么“正则表达式”(R ...
- C语言之枚举数据类型
枚举数据类型概述:1.枚举类型是C语言的一种构造类型.它用于声明一组命名的常数,2.当一个变量有几种可能的取值时,可以将它定义为枚举类型.3.枚举类型是由用户自定义的由多个命名枚举常量构成的类型,其声 ...
- css控制div等比高度
在移动端开发中,在banner轮播图未加载出来之前,banner层是不占文档流高度的,当从服务器获取完banner数据,展示的时候,banner层因为有了内容 所以会撑开,导致banner层下面的内容 ...
- cogs 1316. 数列操作B 区间修改 单点查询
1316. 数列操作B ★★ 输入文件:shulieb.in 输出文件:shulieb.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 假设有一个大小为 n(n ...
- 每天玩转3分钟 MyBatis-Plus - 1. 配置环境
每天玩转3分钟 MyBatis-Plus - 1. 配置环境 每天玩转3分钟 MyBatis-Plus - 2. 普通查询 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 ...
- IDEA中的JUNIT测试
安装插件 Ctrl+Alt+s→Plugins→junitgenerator v2.0 Alt+insert 选中JUnit test 中JUnit4 package test.com.demo.co ...
- 【WPF学习】第十三章 理解路由事件
每个.NET开发人员都熟悉“事件”的思想——当有意义的事情发生时,由对象(如WPF元素)发送的用于通知代码的消息.WPF通过事件路由(event routing)的概念增强了.NET事件模型.事件路由 ...