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的更多相关文章

随机推荐

  1. jSignature签字板保存为图片

    这是本人的第一篇博客,还不会使用.有些简陋,勿怪! 今天要讲的是使用jquery插件jSignature做一个手写板签字的功能,并将签字笔迹保存为图片. 第一步:环境准备 jquery.jSignat ...

  2. 【转】Algorithms -离散概率值(discrete)和重置、洗牌(shuffle)算法及代码

    离散概率值(discrete) 和 重置\洗牌(shuffle) 算法 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/1 ...

  3. Linux Cgroup浅析

    cgroup从2.6.4引入linux内核主线,目前默认已启用该特性.在cgroup出现之前,只能对一个进程做资源限制,比如通过sched_setaffinity设置进程cpu亲和性,使用ulimit ...

  4. 基于Netty和SpringBoot实现一个轻量级RPC框架-Server篇

    前提 前置文章: Github Page:<基于Netty和SpringBoot实现一个轻量级RPC框架-协议篇> Coding Page:<基于Netty和SpringBoot实现 ...

  5. 记一次docker镜像导出导入流程

    目标:导出测试环境的镜像到本地机器 过程: 测试机: docker save -o /Dockerfile/crontabService/php72.tar lnmp72:v1.4 压缩,要不文件太大 ...

  6. python中常⽤的excel模块库

    python中常用的excel模块库&安装方法 openpyxl openpyxl是⼀个Python库,用于读取/写⼊Excel 2010 xlsx / xlsm / xltx / xltm⽂ ...

  7. mysql累加、累减

    累加 先上表结构: CREATE TABLE `abc` ( `jidu` ) NOT NULL AUTO_INCREMENT, `jine` ) DEFAULT NULL, PRIMARY KEY ...

  8. C#中TripleDES对应Java中的DESede即大家说的3DES,附C#及Java加解密结果一致的控制台程序例子

    直接上代码了. Java控制台代码: package Test; import java.security.Key; import javax.crypto.Cipher; import javax. ...

  9. Flsak学习笔记(1)

    Day 01 最近项目里要用python写后端,同学推荐了flask框架就来学一学.写这个博客的目的主要是记录一下自己学习的内容,有基础知识忘了不用一个个去百度,还有就是跟大家分享一下,有不是很容易理 ...

  10. 高通量计算框架HTCondor(一)——概述

    目录 1. 正文 2. 目录 3. 参考 4. 相关 1. 正文 HTCondor是威斯康星大学麦迪逊分校构建的分布式计算软件和相关技术,用来处理高通量计算(High Throughput Compu ...