H:题目看错 背锅

#include <bits/stdc++.h>
#include <vector>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-9;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e4 + ;
const int maxm = ;
vector<pair<int, int> > p[];
int visit[maxn];
int ans[maxn];
int anser = ;
void dfs(int cur)
{
int len = p[cur].size();
if (len == )
{
ans[cur] = ;
}
for (int i = ; i < len; i++)
{
int to = p[cur][i].first;
int lenth = p[cur][i].second;
if (ans[to] != -)
{
ans[cur] = max(ans[cur], ans[to] + lenth);
}
else
{
dfs(to);
ans[cur] = max(ans[cur], ans[to] + lenth);
}
}
}
int main()
{
int t;
cin >> t;
while (t--)
{
anser = ;
mem(visit, );
mem(ans, -);
int n, m;
int from, to, lenth;
cin >> n >> m;
for (int i = ; i <= m; i++)
{
scanf("%d %d %d", &from, &to, &lenth);
visit[to] = ;
p[from].pb(make_pair(to, lenth));
}
for (int i = ; i <= n; i++)
{
if (visit[i] == )
{
//cout<<i<<endl;
dfs(i);
anser = max(anser, ans[i]);
}
}
cout << anser << endl;
for (int i = ; i <= n; i++)
{
p[i].clear();
}
}
}

G:每个test 后面没换行 背锅

#include <bits/stdc++.h>
#include <vector>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-9;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e5 + ;
const int maxm = ;
int n, m, i, num[], tree[], l, r;
char s[maxn], t[maxn];
int slen, tlen, lencha;
string ch, ch1;
int lowbit(int x)
{
return x & (-x);
}
void update(int x, int p)
{
while (x <= n)
{
tree[x] += p;
x += lowbit(x);
}
return;
}
int sum(int k)
{
int ans = ;
while (k > )
{
ans += tree[k];
k -= lowbit(k);
}
return ans;
}
int ask(int l, int r)
{
return sum(r) - sum(l - );
}
int main()
{
/*cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>num[i];
update(i,num[i]);
}
for(i=1;i<=m;i++)
{
cin>>l>>r;
cout<<ask(l,r)<<endl;
}*/
int time;
cin >> time;
while (time--)
{
//mem(num, 0);
mem(tree, );
int now;
scanf("%d",&m);
scanf("%s", s + );
scanf("%s", t);
slen = strlen(s + );
tlen = strlen(t);
//cout<<slen<<" "<<tlen<<endl;
lencha = slen - tlen + ;
n = slen;
for (int i = ; i <= lencha; i++)
{
for (int j = ; j <= tlen; j++)
{
if (j == tlen)
{
num[i] = ;
update(i, num[i]);
break;
}
if (s[i + j] != t[j])
{
num[i] = ;
update(i, num[i]);
break;
} }
}
/*for (int i = 1; i <= slen; i++)
{
cout << num[i] << " ";
}
cout << endl;*/
for (int i = ; i <= m; i++)
{
cin >> ch;
if (ch[] == 'Q')
{
scanf("%d %d", &l, &r);
printf("%d\n", ask(l, r - tlen + ));
}
else if (ch[] == 'C')
{
int flag = ;
scanf("%d", &now);
cin >> ch1;
if (s[now] != ch1[])
{
flag = ;
}
s[now] = ch1[];
int from = max(, now - tlen + );
int to = min(lencha, now);
if (flag)
{
for (int j = from; j <= to; j++)
{
if (num[j] == )
{
num[j] = ;
update(j, -);
}
else
{
for (int k = ; k <= tlen; k++)
{
if (k == tlen)
{
num[j] = ;
update(j, );
break;
}
if (s[j + k] != t[k])
{
break;
}
}
}
}
}
/*for (int i = 1; i <= slen; i++)
{
cout << num[i] << " ";
}
cout << endl;*/
}
}
puts("");
}
return ;
}

J!!!!!!:最小费用最大流

每个城市拆成出点和入点,源点连西安和大连,汇点连上海,相当于求从西安到上海和从大连到上海最小距离之和,每个城市入点和出点之间连一条容量为1的边,但是注意,上海的容量必须是2,再根据给出的边,分别连接出点入点,存入相应花费,那么问题就可以转化成最小费用最大流了,如果流量不为2输出-1,否则输出最小花费。

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<map>
#include<queue>
#include<string>
using namespace std;
#define ll long long
const ll maxm = ;
const ll INF = 1e18 + ;
struct node
{
ll u, v, flow, cost, next;
}edge[maxm * ];
map<string, ll>p;
ll cnt, s, t, n, m, sum, FLOW;
ll head[maxm * ], dis[maxm * ], pre[maxm * ];
char a[maxm], b[maxm];
void init()
{
p.clear();
cnt = , s = , t = n * + , sum = , FLOW = ;
memset(head, -, sizeof(head));
}
void add(ll u, ll v, ll flow, ll cost)
{
edge[cnt].u = u, edge[cnt].v = v;
edge[cnt].flow = flow, edge[cnt].cost = cost;
edge[cnt].next = head[u], head[u] = cnt++;
edge[cnt].u = v, edge[cnt].v = u;
edge[cnt].flow = , edge[cnt].cost = -cost;
edge[cnt].next = head[v], head[v] = cnt++;
}
ll bfs()
{
queue<ll>q;
for (ll i = ;i <= t;i++) dis[i] = INF;
memset(pre, -, sizeof(pre));
dis[s] = , q.push(s);
ll rev = ;
while (!q.empty())
{
ll u = q.front();q.pop();
for (ll i = head[u];i != -;i = edge[i].next)
{
ll v = edge[i].v;
if (dis[v] > dis[u] + edge[i].cost&&edge[i].flow)
{
dis[v] = dis[u] + edge[i].cost;
pre[v] = i, q.push(v);
}
}
}
if (dis[t] == INF) return ;
return ;
}
ll MCMF()
{
ll ans = , minflow;
while (bfs())
{
minflow = INF;
for (ll i = pre[t];i != -;i = pre[edge[i].u])
minflow = min(minflow, edge[i].flow);
for (ll i = pre[t];i != -;i = pre[edge[i].u])
edge[i].flow -= minflow, edge[i ^ ].flow += minflow;
ans += dis[t] * minflow;
FLOW += minflow;
}
return ans;
}
int main()
{
ll i, j, k, T, c;
scanf("%lld", &T);
while (T--)
{
scanf("%lld", &n);
init();
ll nn = n * ;
for (i = ;i <= n;i++)
{
scanf("%s%s%lld", a, b, &c);
if (p[a] == )
{
p[a] = ++sum, k = ;
if (strcmp(a, "Shanghai") == ) k = ;
add(p[a], p[a] + nn, k, );
}
if (p[b] == )
{
p[b] = ++sum, k = ;
if (strcmp(b, "Shanghai") == ) k = ;
add(p[b], p[b] + nn, k, );
}
ll u = p[a], v = p[b];
add(u + nn, v, INF, c);
add(v + nn, u, INF, c);
}
ll u = p["Dalian"];
add(s, u, , );
u = p["Xian"];
add(s, u, , );
u = p["Shanghai"];
add(u + nn, t, , );
ll ans = MCMF();
if (FLOW == ) printf("%lld\n", ans);
else printf("-1\n");
}
return ;
}

2017 ICPC 乌鲁木齐的更多相关文章

  1. 2017 ICPC乌鲁木齐 A Coins 概率dp

    Coins 题意:一开始所有n个硬币都是反面朝上的,每次必须拿k个来抛,抛的人足够聪明,问m次之后向上的硬币的期望. 首先说了这个足够聪明的意思,就是只要向反面的有k个就不会sb地去拿向正面的来抛,想 ...

  2. 【2017 ACM/ICPC 乌鲁木齐赛区网络赛环境测试赛 E】蒜头君的排序

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 莫队算法+树状数组. 区间增加1或减少1. 对逆序对的影响是固定的. (用冒泡排序变成升序的交换次数,就是逆序对的个数) [错的次数] 0 [ ...

  3. 2017 icpc 沈阳网络赛

    cable cable cable Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. 2017 ICPC 广西邀请赛1004 Covering

    Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. 2017 ICPC区域赛(西安站)--- J题 LOL(DP)

    题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...

  6. Bumped! 2017 ICPC North American Qualifier Contest (分层建图+dijstra)

    题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his return flight ...

  7. 2017 ICPC网络赛(西安)--- Xor

    题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai​≤1,000 ...

  8. 2017 ICPC西安区域赛 A - XOR (线段树并线性基)

    链接:https://nanti.jisuanke.com/t/A1607 题面:   Consider an array AA with n elements . Each of its eleme ...

  9. 2017 ICPC 广西邀请赛1005 CS Course

    CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 059. Spiral Matrix II

    题目链接:https://leetcode.com/problems/spiral-matrix-ii/description/ Given a positive integer n, generat ...

  2. 2019CVPR:Classification-Reconstruction Learning for Open-Set Recogition(Abstract)

    Abstract Open-set classification is a problem of handling 'unknown' classes that are not contained i ...

  3. 蓝鲸 修改主机名重装后初始化不了cmdb安装不了job + 数据采集流程

    1.表象:在部署蓝鲸JOB过程中需要进行RabbitMQ的安装,数据初始化,激活步骤,此问题多发生在此过程 [ root@rbtnodel install)# ./bkcec initdata rab ...

  4. yum tenxun ntpdate 时间同步

    centos7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base ...

  5. win10任务切换变卡

    问题:更新之前没有任何问题,用alt+tab是秒切,更新后切换任务后会黑屏一两秒然后才转到切换页面 解决方法:关闭服务“system interface foundation service”

  6. sql server 查询某段日期某段时间内的数据

    如我要取8月1号到8月30号之间的早上7点半到晚上八点半这段时间内的数据. SELECT * FROM tableName AS tWHERE t.create_date BETWEEN '2017- ...

  7. HTML5自学

    1.1   标题文本 在HTML5中,文本的结构除了以行和段落出现之外,还可以作为标题存在,通常一篇文档最基本的结构就是由不同级别的标题和正文组成的. 例如1:(中国门户网站) https://www ...

  8. linux 安装 python 最全教程

    环境:centos6.5 centos6.5 自带的 python 版本是 2.6.6,需要重新安装 2.7: centos7 自带的 python 版本是 2.7.5 基本操作 在安装新版本之前,一 ...

  9. mysql添加索引造成的影响

    尽管添加索引可以优化SQL语句的性能,但是添加索引的同时也会带来不小的开销.尤其是在有大量的索引的情况下. mysql添加索引造成的影响如下: 1.DML(数据操作语言)影响,在表上添加缩影会直接影响 ...

  10. 全面解析java编码问题

    1.web.xml文件里配置 <filter> <filter-name>CharacterEncodingFilter</filter-name> <fil ...