A.找最小的数,看每个数跟它的差是否被k整除。

#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 ;
}

B.直接dfs记录方向和转弯次数,不做其他剪枝就能过。

#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std; int n,m,vis[][][] = {},x1,Y1,flag = ;
int dx[] = {-,,,};
int dy[] = {,-,,};
string a[]; void dfs(int x,int y,int d,int cnt)
{
if(cnt > ) return;
if(flag) return;
if(a[x][y] == 'T') flag = ;
if(d != -) vis[x][y][d] = ;
for(int i = ;i < ;i++)
{
if((i+)% == d) continue;
int xx = x+dx[i],yy = y+dy[i];
if(xx < || xx > n || yy < || yy > m || a[xx][yy] == '*') continue;
if(vis[xx][yy][i]) continue;
dfs(xx,yy,i,cnt+(i != d));
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i = ;i <= n;i++)
{
cin >> a[i];
a[i] = " "+a[i];
}
for(int i = ;i <= n;i++)
{
for(int j = ;j <= m;j++)
{
if(a[i][j] == 'S') x1 = i,Y1 = j;
}
}
dfs(x1,Y1,-,-);
if(flag) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}

C.遍历每只老鼠,一次次缩小时间区间,最后考虑可能性,注意速率为0和边缘情况。

#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std; int n,flag = ;
double ansl = ,ansr = 1e9; void f(int x,int v,int l,int r)
{
if(v == && (x <= l || x >= r))
{
flag = ;
return;
}
double t = 1.0*(l-x)/v,tt = 1.0*(r-x)/v;
ansl = max(ansl,min(t,tt));
ansr = min(ansr,max(t,tt));
} int main()
{
ios::sync_with_stdio(false);
cin >> n;
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2; for(int i = ;i <= n;i++)
{
int a,b,c,d;
cin >> a >> b >> c >> d;
f(a,c,x1,x2);
f(b,d,y1,y2);
}
if(flag == && ansl < ansr) cout << fixed << setprecision() << ansl << endl;
else cout << - << endl;
return ;
}

D.暴力每一个起点,每次移动,更新区间,记忆化一下,dp[i][j][k][l]表示当前在i,可行区间(j,k),已经经过l个点。

#include<bits/stdc++.h>
using namespace std; int n,m,k,g[][],dp[][][][]; int dfs(int now,int l,int r,int cnt)
{
int &ans = dp[now][l][r][cnt];
if(ans != -) return ans;
if(cnt == k)
{
ans = ;
return ;
}
ans = 1e9;
for(int i = l+;i < r;i++)
{
if(g[now][i] == 1e9) continue;
int x = l,y = r;
if(now < i) x = now;
else y = now;
ans = min(ans,g[now][i]+dfs(i,x,y,cnt+));
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin >> n >> k >> m;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= n;j++) g[i][j] = 1e9;
}
memset(dp,-,sizeof(dp));
for(int i = ;i <= m;i++)
{
int x,y,z;
cin >> x >> y >> z;
g[x][y] = min(g[x][y],z);
}
int ans = 1e9;
for(int i = ;i <= n;i++) ans = min(ans,dfs(i,,n+,));
if(ans == 1e9) cout << - << endl;
else cout << ans << endl;
return ;
}

Codeforces_793的更多相关文章

随机推荐

  1. .NET Core 3.1和WorkerServices构建Windows服务

    介绍 ASP.NET Core 3增加了一个非常有意思的功能Worker Service.他是一个ASP.NET Core模板,他允许我们创建托管长期的运行的后台服务,这些服务具体实现IHostedS ...

  2. CentOS7.2 部署Ceph分布式存储

    1.1 环境准备 主机名 IP地址 ceph-admin 192.168.16.220 ceph-node1,ceph-mon 192.168.16.221 ceph-node2,ceph-mon 1 ...

  3. 2019 年百度之星 初赛一 1002 Game

    传送门 Problem Description 度度熊在玩一个好玩的游戏.游戏的主人公站在一根数轴上,他可以在数轴上任意移动,对于每次移动,他可以选择往左或往右走一格或两格.现在他要依次完成 n 个任 ...

  4. 简单工厂模式(C++)

    #include <iostream> using namespace std; class Fruit { public : ; }; class Banana :public Frui ...

  5. 简单的c语言程序

    我猜大部分人第一门掌握的语言是c语言吧(我第一门学的是python). 在接下来的文章里我会逐步的介绍有关自己对c语言的理解,希望对一些小伙伴有帮助,有哪里有错误希望大佬指出. 首先这是第一个c语言程 ...

  6. HTML中使用Vue+Dhtmlxgantt制作任务进度图

    HTML中使用Vue+Dhtmlxgantt制作任务进度图 Dhtmlxgantt官网: https://dhtmlx.com/docs/products/dhtmlxGantt/ 参考文章 甘特图配 ...

  7. head查询

    • must子句:文档必须匹配must查询条件:• should子句:文档应该匹配should子句查询的一个或多个:• must_not子句:文档不能匹配该查询条件:• filter子句:过滤器,文档 ...

  8. Nginx作为web静态资源服务器——防盗链

    ​ 基于http_refer防盗链配置模块 Syntax:valid_referers none | blocked | server_names | string ...; Default:—— C ...

  9. GP工作室—Alpha版本发布1

    目录 GP工作室-Alpha版本发布1 一.简介 1.1作业要求 1.2团队成员 二.软件下载安装说明 五.项目总结 @(Gold Point团队の项目计划) GP工作室-Alpha版本发布1 一.简 ...

  10. 史上最详细的二叉树、B树,看不懂怨我

    今天我们要说的红黑树就是就是一棵非严格均衡的二叉树,均衡二叉树又是在二叉搜索树的基础上增加了自动维持平衡的性质,插入.搜索.删除的效率都比较高.红黑树也是实现 TreeMap 存储结构的基石. 1.二 ...