A. Palindromic Twist

给一个字符串(小写字母)   每个字符+1,-1;变成其他字符  a只能变b  z只能变y 看能否变成回文字符串

#include<bits/stdc++.h>
using namespace std;
int32_t main()
{
int T; cin>>T;
while(T--)
{
int n; cin>>n;
string ss; cin>>ss;
int t=;
for(int i=;i<n/;i++)
{
if(ss[i]-ss[n--i]==||fabs(ss[i]-ss[n--i])==)
continue;
else t=;
}
if(t==) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
}

A.cpp

B. Numbers on the Chessboard

分类讨论下就ok了

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=1e5+;
const int INF=0x3f3f3f3f;
int32_t main()
{
int n,q; cin>>n>>q;
if(n%==)
{
int ans1=;
int ans2=n*n/;
while(q--)
{
int a,b;cin>>a>>b;
if( (a+b)%== ) cout<<ans1+(a-)*n/+(b+)/<<endl;
else cout<<ans2+(a-)*n/+(b+)/<<endl;
}
}
else if(n%==)
{
int ans1=;
int ans2=n*n/+;
while(q--)
{
int a,b;cin>>a>>b;
if( (a+b)%== )
{
if(a%==) cout<<(a-)/*n+(b+)/<<endl;
else if(a%==) cout<<(a-)/*n+(n+)/+(b+)/<<endl;
}
else
{
if(a%==) cout<<ans2+(a-)/*n+(b+)/<<endl;
else if(a%==) cout<<ans2+(a-)/*n+(n-)/+(b+)/<<endl;
}
}
}
}

B.cpp

C. Minimum Value Rectangle

要使    4*(a+b)(a+b)/a*b  (a<b) 即使  b/a 最小  排序后暴力也可以   直接找b/a 最小也行。

#include<bits/stdc++.h>
#define int long long
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned long long uLL;
using namespace std;
const int maxn=3e6+;
const int INF=0x3f3f3f3f;
int a[maxn];
int b[maxn];
int32_t main()
{ios::sync_with_stdio(false); cin.tie(); cout.tie();
int T;cin>>T;
while(T--)
{ int n; cin>>n;
for(int i=;i<=n;i++) cin>>a[i];
sort(a+,a++n);
int t=;
for(int i=;i<n;i++)
{
if(a[i]!=a[i+]) continue;
else { b[++t]=a[i]; i++;}
}
double ans=1e18;
int x,y;
for(int i=;i<t;i++)
{
double c=(b[i]*1.000000000000/b[i+])+b[i+]*1.000000000000/b[i];
if(c<ans)
{
ans=c;
x=b[i]; y=b[i+];
}
}
cout<<x<<" "<<x<<" "<<y<<" "<<y<<endl;
}
}

C.cpp

D. Mouse Hunt

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
int c[maxn];
int a[maxn];
int x[maxn];
int sst[maxn];
int ffind(int x)
{
if(x==sst[x]) return x;
return sst[x]=ffind(sst[x]);
}
int dfs(int x, int y){
if(x == y) return c[x];
return min(dfs(a[x], y), c[x]);
}
int main()
{
int n; cin>>n;
for(int i=;i<=n;i++) cin>>c[i];
for(int i=;i<=n;i++) sst[i]=i ;
for(int i=;i<=n;i++) cin>>a[i];
for(int i=;i<=n;i++)
{
if(ffind(a[i])==ffind(i))
{
x[i]=;
// continue;
}
else
{
sst[ffind(a[i])]=ffind(i);
}
/* for(int i=1;i<=n;i++)
{
cout<<i<<"=="<<sst[i]<<" ";
}cout<<endl;
for(int i=1;i<=n;i++)
{
cout<<x[i]<<"---- ";
}cout<<endl;*/
}
int ans = ;
for(int i = ; i <= n; i++)
{
//cout<<i<<endl;
if(x[i]) ans += dfs(a[i], i);
//cout<<ans<<endl;
}
printf("%d\n", ans);
return ;
}

D.cpp

R49 A-D D图有向有环图的更多相关文章

  1. 图->有向无环图->求关键路径

    文字描述 与AOV-网相对应的是AOE-网(Activity on Edge)即边表示活动的网.AOE-网是一个带权的有向无环图.其中,顶点表示事件Event,弧表示活动,权表示活动持续的时间.通常, ...

  2. 图->有向无环图->拓扑排序

    文字描述 关于有向无环图的基础定义: 一个无环的有向图称为有向无环图,简称DAG图(directed acycline graph).DAG图是一类较有向树更一般的特殊有向图. 举个例子说明有向无环图 ...

  3. 有向无环图的应用—AOV网 和 拓扑排序

    有向无环图:无环的有向图,简称 DAG (Directed Acycline Graph) 图. 一个有向图的生成树是一个有向树,一个非连通有向图的若干强连通分量生成若干有向树,这些有向数形成生成森林 ...

  4. UML 用例图、顺序图、状态图、类图、包图、协作图、流程图

    ​用例图.顺序图.状态图.类图.包图.协作图 面向对象的问题的处理的关键是建模问题.建模可以把在复杂世界的许多重要的细节给抽象出.许多建模工具封装了UML(也就是Unified Modeling La ...

  5. 桌面显卡天梯图和桌面cpu天梯图

    桌面cpu天梯图: 桌面显卡天梯图:

  6. 数据结构-图-Java实现:有向图 图存储(邻接矩阵),最小生成树,广度深度遍历,图的连通性,最短路径1

    import java.util.ArrayList; import java.util.List; // 模块E public class AdjMatrixGraph<E> { pro ...

  7. JavaScript + SVG实现Web前端WorkFlow工作流DAG有向无环图

    一.效果图展示及说明 (图一) (图二) 附注说明: 1. 图例都是DAG有向无环图的展现效果.两张图的区别为第二张图包含了多个分段关系.放置展示图片效果主要是为了说明该例子支持多段关系的展现(当前也 ...

  8. 图结构练习——判断给定图是否存在合法拓扑序列(dfs算法(第一个代码),邻接矩阵(前两个代码),邻接表(第三个代码))

    sdut 2140 图结构练习——判断给定图是否存在合法拓扑序列 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述  给定一个有向图 ...

  9. 湖南省第十二届大学生计算机程序设计竞赛 B 有向无环图 拓扑DP

    1804: 有向无环图 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 187  Solved: 80[Submit][Status][Web Board ...

随机推荐

  1. windows 网络操作

    ver 命令 显示当前机器上的操作系统版本信息 ipconfig/release 释放IP地址 ipconfig/renew 重新获取IP地址 cmd下使用ssh 如果想在cmd中输入 ssh xx@ ...

  2. C# 表达式树学习笔记

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  3. Cracking The Coding Interview 5.5

    #include <iostream> #include <vector> using namespace std; int getNum1(int N) { int num= ...

  4. Oracle学习(四)_SQL函数

    --第一部分:SQL基础 --ch1 简单查询 --ch2 查询基本概念 --ch3 数据过滤 --第二部分:多表操作 --ch4 集合理论 --ch5 内连接 --ch6 外连接 --ch7 子查询 ...

  5. oracle语句优化

    摘录来自https://blog.csdn.net/sap_jack/article/details/3766703 1.选用适合的Oracle优化器 Oracle的优化器共有3种: a.RULE(基 ...

  6. <Yarn><Node Labels>

    Go through official docs For the official docs of Yarn node label, plase see here. Overview Node lab ...

  7. centos/7下安装mysql5.7

    本文参考自:https://blog.csdn.net/fanshujuntuan/article/details/78077433 背景:在ubuntu下用vagrant搭建了一个集群环境, 每个虚 ...

  8. python自学第三天,列表

    1.列表 names=[] #这就是一个空列表 names=[1,5,2,3,4,5]#列表是用的中括号,每个元素是用逗号分开的.列表里面的元素是可以重复的. names[-1]#表示的是取列表的最后 ...

  9. 解决You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order (order_name, customer)

    在学习hibernate一对多映射关系时,根据视频学习的时候,例子是顾客和订单的问题,一个顾客有多个订单.按照视频中的敲代码出现了You have an error in your SQL synta ...

  10. centos安装python3虚拟环境和python3安装

    1.本文的系统命令一般会在语句前加上#号,以区分系统命令及其他内容.输入命令时,无需输入#号. # yum install vim 2.本文系统输出的信息,会在前面加上>>号. # whi ...