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)遗憾题合集的更多相关文章

  1. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  2. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  3. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题

    A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...

  7. Codeforces Round #374 (Div. 2) B. Passwords —— 基础题

    题目链接:http://codeforces.com/contest/721/problem/B B. Passwords time limit per test 2 seconds memory l ...

  8. 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 ...

  9. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

随机推荐

  1. Oracle数据库表复制语句

    Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) values(value1,value2,...)这种形式的在应用程序开发中必不可少.但我 ...

  2. firebox httprequester 模拟请求

    获取下载插件 httprequester 模拟POST请求,必须点击Parameter Body 参数写法:abc=123&id=456 也可以选择Headers栏目添加

  3. 已知一个日期和天数, 求多少天后的日期(是那个超时代码的AC版)

    #include <stdio.h> #include <string.h> ; int judge_year(int x) { == || x % == && ...

  4. NY-字符串替换

    描述编写一个程序实现将字符串中的所有"you"替换成"we" 输入 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 输出 对于输入 ...

  5. ubuntu安装Python环境以及科学计算环境

    参考:http://blog.csdn.net/a1311543690/article/details/ 1.sudo apt-get install python-pip pip是Python的一个 ...

  6. sphinx网址

    http://www.phperz.com/article/14/0615/95.htmlhttp://www.kuqin.com/shuoit/20141101/342963.htmlhttp:// ...

  7. laravel 4.2 session

    laravel的session简要API Session的API还是比较简单的,大家看看中文文档也大概知道是怎么个意思.但是有那么几个还不太好理解. //session的永久保存(在不过期范围内) S ...

  8. ThinkPHP 3.2.3 数据缓存与静态缓存

    ThinkPHP 3.2.3 中手册中数据缓存的地址是:http://www.kancloud.cn/manual/thinkphp/1835 静态缓存的地址是:http://www.kancloud ...

  9. ios-实现项目在开发、测试、正式环境快速部署

    快速部署:简单的来说,就是不用更改开发.测试.正式环境下的 url ,来实现在同一台测试手机快速部署三种项目状态. Bundle ID一样只会出现一个app:不一样会出现三个app: 具体步骤: 一. ...

  10. 【java基础学习】泛型

    泛型 1. 泛型类(声明的泛型类型静态方法不能使用) class Tools<T>{ private T t; public void set(T t){ this.t = t; } pu ...