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. 侠说java8-行为参数化(开山篇)

    啥是行为参数化 行为参数化的本质是不执行复杂的代码块,让逻辑清晰可用. 相信使用过js的你肯定知道,js是可以传递函数的,而在 java中也有类似的特性,那就是匿名函数. 理解:行为参数化是一种方法, ...

  2. Oracle数据库设计省市区小区数据库建表

    省CREATE TABLE "SF_JECF_BASE"."SF_PROVINCE" ( "id" VARCHAR2(64 BYTE) NO ...

  3. 杂谈.netcore的Buffer相关新类型

    1 文章范围 本文将.netcore新出现的与Buffer操作相关的类型进行简单分析与讲解,由于资料有限,一些见解为个人见解,可能不是很准确.这些新类型将包括BinaryPrimitives.Span ...

  4. 到底如何配置 maven 编译插件的 JDK 版本

    千言万语不及官方文档,详情请阅读 compiler:compile 文档 配置 maven 编译插件的 JDK 版本 maven 编译插件(maven-compiler-plugin)有默认编译 JD ...

  5. Sentinel :微服务哨兵

    1. Sentinel 是什么? 随着微服务的流行,服务和服务之间的稳定性变得越来越重要.Sentinel 以流量为切入点,从流量控制.熔断降级.系统负载保护等多个维度保护服务的稳定性. Sentin ...

  6. C#调用Fortran生成的DLL的方法报内存不足

    最近在研究一个程序,公司给的,程序是VB写的,程序里面还有一个计算的模型,用Fortran语言写的. 在调试到这个模型里面的方法时报错,说是内存不足,于是就在网上查找方法,看了两篇博客之后问题解决了. ...

  7. Java 数据结构快速入门

    数据结构:栈 简介 栈(stack),又称堆栈,它是运算受限的线性表. 限制 栈(stack)的限制是仅允许在标的一端进行插入和删除操作,不允许在其他任何位置进行添加.查找.删除等操作. 采用该结构的 ...

  8. cogs 397. [USACO Oct09] 热浪 Dijkstra

    397. [USACO Oct09] 热浪 ★☆   输入文件:heatwvx.in   输出文件:heatwvx.out   简单对比时间限制:1 s   内存限制:128 MB 德克薩斯純樸的民眾 ...

  9. Mysql-SQL优化-子查询替代LEFT JOIN

    表A:批次信息表, 表B:实际批次明细表, Mysql版本:5.6.36 两表之间的数据体量差异:表B是表A的10000倍. 经过结转,表B通常保留 1千5百万数据.表A就是1千多条数据. 计算近24 ...

  10. 实验五:配置Eth-Trunk链路聚合(手工负载分担模式)

    1.配置图 2.配置命令 LSW1的eth trunk 1配置如下: 配置命令如下: [S1]Eth-Trunk1 创建Eth-Trunk1端口 [S1-Eth-Trunk1]mode lacp-st ...