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的更多相关文章
随机推荐
- CSRF 详解:攻击,防御,Spring Security应用等
本文原创,更多内容可以参考: Java 全栈知识体系.如需转载请说明原处. CSRF(Cross-site request forgery跨站请求伪造,也被称成为"one click att ...
- mysql 执行计划查看
使用explain关键字可以模拟优化器执行SQL查询语句,从而知道MySQL是如何处理你的SQL语句的,分析你的查询语句或是表结构的性能瓶颈.explain执行计划包含的信息 其中最重要的字段为:id ...
- C++ | C++ 基础知识 | 结构、联合与枚举
1. 结构 1.0 结构 数组是相同类型元素的集合,相反,struct 是任意类型元素的集合. 代码例子: struct Address { const char* name; int number; ...
- nginx负载均衡动态自动更新(微博开源模块nginx-upsync-module使用)
这几天项目有个需求:负载要求能根据节点健康状态动态的增减.nginx自带的upstram已经很强大,而且基于Nginx Upstream配置动态更新已经有很多开源方案,大多数都是基于生成配置文件后进行 ...
- 如何应用threejs实现立方体每个面用图片替换
var geometry = new THREE.BoxGeometry(200, 200, 200);var materialsbg = []; for (var i = 0; i < geo ...
- 一款精美的Toast第三方库的简单使用
以前一直用的安卓原生Toast,个人感觉Toast这东西,没必要花功夫,知道看到了Toasty这东西,立刻被圈粉了,真的非常好看. 项目地址 我们都知道,安卓原生Toast的用法是 Toast.mak ...
- C# HttpWebRequest传递参数多种方式混合使用
在做CS调用第三方接口的时候遇到了这样的一个问题,通过PSOTman调试需要分别在parmas.Headers.Body里面同时传递参数.在网上查询了很多资料,以此来记录一下开发脱坑历程. POSTm ...
- 一个命令解决linux重启nginx就丢失pid文件问题
sudo nginx -c /etc/nginx/nginx.conf
- 《C# 爬虫 破境之道》:第一境 爬虫原理 — 第三节:WebResponse
第二节中,我们介绍了WebRequest,它可以帮助我们发送一个请求,不过正所谓“来而不往非礼也”,对方收到我们的请求,不给点回复,貌似不太合适(不过,还真有脸皮厚的:P). 接下来,就重点研究一下, ...
- 异数OS-织梦师-PBFT(六) 走出区块链,加速破解PBFT
. 异数OS-织梦师-PBFT(六) 走出区块链,加速破解PBFT 拜占庭 本文来自异数OS社区 github: https://github.com/yds086/HereticOS 异数OS社区Q ...