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. Go中锁的那些姿势,估计你不知道

    什么是锁,为什么使用锁 用俗语来说,锁意味着一种保护,对资源的一种保护,在程序员眼中,这个资源可以是一个变量,一个代码片段,一条记录,一张数据库表等等. 就跟小孩需要保护一样,不保护的话小孩会收到伤害 ...

  2. 全网最详细的Linux命令系列-sed文本处理命令

    Sed简介 SED是一个非交互式文本编辑器,它可对文本文件和标准输入进行编辑,标准输入可以来自键盘输入.文本重定向.字符串.变量,甚至来自于管道的文本,与VIM编辑器类似,它一次处理一行内容,Sed可 ...

  3. 重拾c++第四天(7):函数相关

    1.引用变量: int a; int &b = a; //引用变量 指向同一地址,必须在初始化时定义,且一直对原变量献上忠诚,主要针对类对象 2.函数重载最好用在功能相同,但数据类型不同的情况 ...

  4. 通过ArcGIS将数据存储到SQL Server2012中

    一.软件安装: ARCGIS 10.3安装 SQLserver2012安装 ARCGIS 10.3 安装(注意ARCGIS10.3并不用安装配置ARCSDE). https://wenku.baidu ...

  5. 失衡天平 - 简单dp

    链接:https://www.nowcoder.com/acm/contest/186/C来源:牛客网 终于Alice走出了大魔王的陷阱,可是现在傻傻的她忘了带武器了,这可如何是好???这个时候,一个 ...

  6. 发布到远程存储库时遇到错误: Git failed with a fatal error.

    正在推送 master发布到远程存储库时遇到错误: Git failed with a fatal error.Authentication failed for 'http://1212121xxx ...

  7. C#与JavaScript中URL编码解码问题(转)

    混乱的URI编码 JavaScript中编码有三种方法:escape.encodeURI.encodeURIComponent C#中编码主要方法:HttpUtility.UrlEncode.Serv ...

  8. springboot整合@Scheduled定时任务的使用

    1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...

  9. Python解析json字符串,json字符串用法

    json数据简介 json数据是一个轻量级的数据交换格式,采用完全独立于语言的文本格式,这些特性使json称为理想的数据交换语言,易于人阅读和编写,同时易于机器解析和生成. json中的字符集必须是U ...

  10. django.db.migrations.exceptions.MigrationSchemaMissing和raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

    1.使用Python3.7 + Django2.2 + MySQL 5.5 在执行(python manage.py migrate)命令时出现错误django.db.migrations.excep ...