Codeforces Round #374 (div.2)遗憾题合集
C.Journey
读错题目了。。。不是无向图,结果建错图了(喵第4样例是变成无向就会有环的那种图)
并且这题因为要求路径点尽可能多
其实可以规约为限定路径长的拓扑排序,不一定要用最短路做
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar();
x = ;
while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int INF=0x7fffffff;
const int maxn=;
int dp[maxn][maxn];
struct Edge
{
int v,nx; int w;
}e[maxn];
int h[maxn],sz,r[maxn];
int n,m,T;
queue<int>Q;
int pre[maxn][maxn]; void add(int u,int v,LL w)
{
e[sz].v=v; e[sz].w=w;
e[sz].nx=h[u]; h[u]=sz++;
} int main()
{
scanf("%d%d%d",&n,&m,&T); for(int i=;i<=n;i++)
{
h[i]=-;
for(int j=;j<=n;j++)
{
dp[i][j]=INF;
pre[i][j]=-;
}
} for(int i=;i<=m;i++)
{
int u,v; LL w; scanf("%d%d%d",&u,&v,&w);
add(u,v,w); r[v]++;
} dp[][]=;
for(int i=;i<=n;i++) if(r[i]==) Q.push(i);
bool flag=;
while(!Q.empty())
{
int top=Q.front(); Q.pop();
if(top==) flag=;
if(flag==)
{
for(int i=h[top];i!=-;i=e[i].nx)
{
int to=e[i].v;
r[to]--;
if(r[to]==) Q.push(to);
}
continue;
}
for(int i=h[top];i!=-;i=e[i].nx)
{
int to=e[i].v;
for(int j=;j<=n;j++)
{
if(dp[top][j-]==INF) continue;
if(dp[top][j-]+e[i].w>T) continue;
if(dp[top][j-]+e[i].w>=dp[to][j]) continue; pre[to][j]=(top-)*n+j--;
dp[to][j]=dp[top][j-]+e[i].w;
}
r[to]--;
if(r[to]==) Q.push(to);
}
} int sum;
for(int i=;i<=n;i++) if(dp[n][i]<=T) sum=i; cout<<sum<<endl;
int nowx=n,nowy=sum; stack<int>S;
while()
{
S.push(nowx);
int tx,ty;
tx=pre[nowx][nowy]/n; tx++;
ty=pre[nowx][nowy]%n; ty++;
if(pre[nowx][nowy]==-) break;
nowx=tx; nowy=ty;
}
while(!S.empty())
{
cout<<S.top()<<" "; S.pop();
} return ;
}
D.Maxim and Array
没时间做。。。被第2、3题耽误了
试算了一下发现并不复杂。。。每次取绝对值最小的数(使其余值的乘积绝对值最大)这样对其加减时,总乘积变化也就最大
太多数了,直接乘会爆long long,直接判断负数个数(总乘积的正负性),以此判断要加要减
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <queue>
#include <math.h>
using namespace std; const int N = + ;
typedef long long ll; ll aabs(ll x) {return x< ? -x : x;} struct node
{
ll num;
int id;
bool operator < (const node & temp) const
{
return aabs(num) > aabs(temp.num);
}
}; ll a[N];
ll n,k,x; int main()
{
cin >> n >> k >> x;
int sign = ;
priority_queue<node> Q;
for(int i=;i<=n;i++)
{
scanf("%I64d",a+i);
if(a[i] < ) sign = -sign;
Q.push((node){a[i],i});
}
while(k--)
{
node temp = Q.top();Q.pop();
if(a[temp.id] < )
{
if(sign == -) a[temp.id] -= x;
else a[temp.id] += x;
if(a[temp.id] >= ) sign = -sign;
}
else
{
if(sign == -) a[temp.id] += x;
else a[temp.id] -= x;
if(a[temp.id] < ) sign = -sign;
}
Q.push((node){a[temp.id],temp.id});
}
for(int i=;i<=n;i++)
{
printf("%I64d%c",a[i],i==n?'\n':' ');
}
}
E.Road to Home
Codeforces Round #374 (div.2)遗憾题合集的更多相关文章
- Codeforces Round #378 (Div. 2) D题(data structure)解题报告
题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...
- Codeforces Round #612 (Div. 2) 前四题题解
这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...
- Codeforces Round #713 (Div. 3)AB题
Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...
- Codeforces Round #552 (Div. 3) A题
题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...
- Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...
- Codeforces Round #374 (Div. 2) B. Passwords —— 基础题
题目链接:http://codeforces.com/contest/721/problem/B B. Passwords time limit per test 2 seconds memory l ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题
题目链接:http://codeforces.com/contest/721/problem/A A. One-dimensional Japanese Crossword time limit pe ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
随机推荐
- JS读写cookie以及中文乱码解决
本文地址:http://www.cnblogs.com/PiaoMiaoGongZi/p/4092489.html 转载请注明. Js获取所有的cookie信息: var cookiename = d ...
- oracle 11g 通过在线重定义方式修改表结构
今天因为要对一套数据库的数据抽取进行io优化,希望通过修改表结构将抽取io降下来,因为抽取只针对标签HAVE_FLAG为"0"的值进行抽取,抽取之后更新HAVE_FLAG为其他值, ...
- php数字操作,高精度函数,保留计算结果小数位
$l = 45456.51; $r = 455778.44; $e = '100.00'; $f= '500.00'; $res = bcadd($l, $r,3);//小数点后的位数,精度就是由这个 ...
- P1026 统计单词个数
题意 给出一段字符串和一个字典,把字符串划分为n个连续的子串,求一种最优的划分方式使字符串所含单词数最大.(详见NOIp2001) 思路 这个题是一个很典型的线性dp,难点主要在预处理上. 理解题意后 ...
- 解决ssh登录后闲置时间过长而断开连接
++++++++++++++++++++++++++++ #!/usr/bin/env bash password_5="Uxxx7"host_5="129.x.x.1 ...
- Javascript模块化编程(一):模块的写法 作者: 阮一峰
声明:转载自阮一峰的网络日志 随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞大,越来越复杂. 网页越来越像桌面程序,需要一个团队分工协作.进度管理. ...
- Mybatis 与 spring mvc
本文是用来小结一下自己mybatis 和spring mvc 学习过程. 在写的过程中发现 http://www.phperz.com/article/15/0127/48684.html 这篇文章里 ...
- WWDC 2013 Session笔记 - iOS7中的多任务
这是我的WWDC2013系列笔记中的一篇,完整的笔记列表请参看这篇总览.本文仅作为个人记录使用,也欢迎在许可协议范围内转载或使用,但是还烦请保留原文链接,谢谢您的理解合作.如果您觉得本站对您能有帮助, ...
- TCP/IP网络编程中socket的行为
一. read/write的语义:为什么会阻塞? 先从write说起: #include <unistd.h>ssize_t write(int fd, const void *buf, ...
- SD卡读写遇到的一些函数
SD_SPI_ReadWriteByte(0XFF): 你的数据线写0xff,就是一直保持高,clk就有了8个,可以说只是发送的数据是0xff,这又不是SD的命令,但是它必须要靠控制器提供时钟才能工作 ...