Codeforces 938 正方形方格最多0/1 足球赛dijkstra建图
A
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 1e9 + ;
string ans;
int n;
string a;
int flag;
bool ok(char x)
{
if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' || x == 'y')
{
return true;
}
return false;
}
int main()
{
cin >> n >> a;
flag = ;
for (int i = ; i < n; i++)
{
if (flag)
{
if (ok(a[i]))
{
continue;
}
else
{
ans += a[i];
flag = ;
}
}
else
{
if (ok(a[i]))
{
flag = ;
ans += a[i];
}
else
{
ans += a[i];
flag = ;
}
}
}
cout << ans << endl;
return ;
}
B
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 1e9 + ;
int number[];
int anser = ;
int main()
{
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
int cur;
cin >> cur;
number[cur] = ;
}
for (int i = ; i <= ; i++)
{
if (number[i])
{
anser = max(anser, i - );
}
}
for (int i = ; i >= ; i--)
{
if (number[i])
{
anser = max(anser, - i);
}
}
cout << anser << endl;
return ;
}
C
N*N的方格里 每个方格可以填0或者1 要求每个M*M的小方格里面必须要有一个0
题目给你一个数 问你有没有一对 N,M使之成立
总共有N^2个方格 因为每个M*M的小方格里面需要有一个0 所以每行和每列最少都需要N/M个0 总共就是(N/M)*(N/M)个0
所以答案就是N^2-(N/M)^2个 利用立方差公式可以分解为 (N+(N/M)*(N-(N/M)=ANS 也就是分解质因数 复杂度T*SQRT X
每次遇到一个N M都要检测是否符合条件
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int main()
{
int n;
cin >> n;
while (n--)
{
int flag = ;
int x;
cin >> x;
if (x == )
{
cout << << " " << << endl;
continue;
}
for (int i = ; i <= ((int)sqrt(x) + ) && (!flag); i++)
{
if (x % i == )
{
int chu;
int beichu;
int a;
a = x / i;
chu = abs(i - a) / ;
if (chu == )
{
continue;
}
beichu = min(i, a) + chu;
int m;
m = beichu / chu;
if (beichu * beichu - (beichu / m) * (beichu / m) == x)
{
cout << beichu << " " << m << endl;
flag = ;
}
//break;
}
}
if (!flag)
{
cout << - << endl;
}
}
}
D
给你N个点 每个点可以都办足球比赛 票价为Ai 同时有M条路(不保证图联通)每条路有COST
问你在城市i的球迷想看球需要的最少的钱(往返加球票钱)
用floyd肯定不行 需要建一个超级源点 然后上堆优化的迪杰斯特拉跑一边 超级源点与原来每个点之间连的边的COST为其票价
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int n, m;
priority_queue<pair<ll, int> > que;
vector<pair<int, ll> > gra[];
ll sdis[];
int visit[];
int main()
{
for (int i = ; i <= ; i++)
{
sdis[i] = 1e18;
}
cin >> n >> m;
int from, to;
ll cost;
for (int i = ; i <= m; i++)
{
scanf("%d %d %lld", &from, &to, &cost);
cost *= 2LL;
gra[from].pb(make_pair(to, cost));
gra[to].pb(make_pair(from, cost));
}
for (int i = ; i <= n; i++)
{
scanf("%lld", &cost);
gra[].pb(make_pair(i, cost));
}
que.push({, });
while (!que.empty())
{
int now = que.top().second;
que.pop();
if (visit[now])
{
continue;
}
visit[now] = ;
int len = gra[now].size();
for (int i = ; i < len; i++)
{
to = gra[now][i].first;
ll value = gra[now][i].second;
if (!visit[to] && sdis[to] > sdis[now] + value)
{
sdis[to] = sdis[now] + value;
que.push({ -sdis[to], to});
}
}
}
for (int i = ; i <= n; i++)
{
cout << sdis[i] << " ";
}
cout << endl;
}
Codeforces 938 正方形方格最多0/1 足球赛dijkstra建图的更多相关文章
- 【转】Codeforces Round #406 (Div. 1) B. Legacy 线段树建图&&最短路
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have ...
- Educational Codeforces Round 25 E. Minimal Labels 拓扑排序+逆向建图
E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #406 (Div. 1) B. Legacy 线段树建图跑最短路
B. Legacy 题目连接: http://codeforces.com/contest/786/problem/B Description Rick and his co-workers have ...
- hdu4106 区间k覆盖问题(连续m个数,最多选k个数) 最小费用最大流 建图巧妙
/** 题目:hdu4106 区间k覆盖问题(连续m个数,最多选k个数) 最小费用最大流 建图巧妙 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4106 ...
- Codeforces 杂题集 2.0
记录一些没有写在其他随笔中的 Codeforces 杂题, 以 Problemset 题号排序 1326D2 - Prefix-Suffix Palindrome (Hard version) ...
- Codeforces Round #523 (Div. 2) E. Politics(最小费+思维建图)
https://codeforces.com/contest/1061/problem/E 题意 有n个点(<=500),标记第i个点的代价a[i],然后分别在这n个点建两棵树,对于每颗树的每个 ...
- CodeForces 786B Legacy(线段树优化建图+最短路)
[题目链接] http://codeforces.com/problemset/problem/786/B [题目大意] 给出一些星球,现在有一些传送枪,可以从一个星球到另一个星球, 从一个星球到另一 ...
- Codeforces Round #545 (Div. 2) E 强连通块 + dag上求最大路径 + 将状态看成点建图
https://codeforces.com/contest/1138/problem/E 题意 有n个城市(1e5),有m条单向边(1e5),每一周有d天(50),对于每个城市假如在某一天为1表示这 ...
- [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)
[Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...
随机推荐
- Vue学习(二) :第一个Vue项目
OS: Windows 10 Home 64bit Chocolatey version: 0.10.13 npm version: 6.4.1 yarn version: 1.16.0 git ve ...
- win10 配置tensorflow环境
1. 在anaconda中新增环境 python3.5, 我使用的是anaconda-navigator 中新增的环境,python版本选择3.5 2. 激活新增加的环境, 注意win下,没有sour ...
- java8 查找字符串中首次出现2次的字母
利用java8的stream函数式编程进行处理 1.实现字母分离 map将整个字符串当成一个单词流来处理 Map<String[], Long> collect14 = Stream.of ...
- python学习笔记:(八)条件语句
if语句,python中if语句的一般形式如下: conditon1为真,执行statement_block_1 condition1为假,判断conition_2,如果condition_2为真,执 ...
- 小姐姐带你一起学:如何用Python实现7种机器学习算法(附代码)
小姐姐带你一起学:如何用Python实现7种机器学习算法(附代码) Python 被称为是最接近 AI 的语言.最近一位名叫Anna-Lena Popkes的小姐姐在GitHub上分享了自己如何使用P ...
- CSS3——注释 id 和 class 选择器 css创建(外部、内部、内联样式表)
注释 /* 注释内容 */ id 和 class 选择器 id ID属性不要以数字开头,数字开头的ID在 Mozilla/Firefox 浏览器中不起作用 < ...
- HTML5——拖放 地理定位 视频 音频 新的input类型
拖放 ————> 设置元素为可拖放 拖动什么 放到何处 进行放置 实例[来回拖放] 地理定位 使用地理定位 处理错误和拒绝 在地图中显示结果 基于脚本的交互式地图 给定位置的信息 用户移动时 ...
- 项目测试完成后,总结典型性bug,以测试的角度,应该怎么筛选bug
一个wap端改版项目完结了,总结下测试过程中的典型性bug:应该从哪个角度去总结? 有点疑问?不知道是以bug的影响度去总结,还是以优先级去总结(好像优先级和影响度是成正比的,优先级比较高的bug,影 ...
- 【MM系列】SAP MM模块-收货自动创建采购订单
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-收货自动创建采购订 ...
- Python--笔试题
一.如何提高Python的运行效率: 1.使用生成器,因为可以节约大量内存 2.循环代码优化,避免过多重复代码的执行 3.核心模块用Cython PyPy等,提高效率 4.多进程.多线程.协程 5.多 ...