C - Sugar Water


Time limit : 3sec / Memory limit : 256MB

Score : 300 points

Problem Statement

Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.

  • Operation 1: Pour 100A grams of water into the beaker.
  • Operation 2: Pour 100B grams of water into the beaker.
  • Operation 3: Put C grams of sugar into the beaker.
  • Operation 4: Put D grams of sugar into the beaker.

In our experimental environment, E grams of sugar can dissolve into 100 grams of water.

Snuke will make sugar water with the highest possible density.

The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted.

We remind you that the sugar water that contains a grams of water and b grams of sugar is

100b
a+b

 percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

Constraints

  • 1≤A<B≤30
  • 1≤C<D≤30
  • 1≤E≤100
  • 100AF≤3 000
  • ABCDE and F are all integers.

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

Print two integers separated by a space. The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.


Sample Input 1

Copy
1 2 10 20 15 200

Sample Output 1

Copy
110 10

In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.

We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once. It is not possible to make sugar water with higher density. For example, the following sequences of operations are infeasible:

  • If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.
  • If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.

Sample Input 2

Copy
1 2 1 2 100 1000

Sample Output 2

Copy
200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.


Sample Input 3

Copy
17 19 22 26 55 2802

Sample Output 3

Copy
2634 934

暴力枚举啊

#include<stdio.h>
int main()
{
int A,B,C,D,E,F,x=,y=;
scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
for(int i=; i<=F/(*A); i++)
{
int a=i**A;
if(a>F) break;
for(int j=; j<=F/(*B); j++)
{
int b=j**B;
if(a+b>F) break;
for(int k=; k<F/C; k++)
{
int c=k*C;
if(a+b+c>F) break;
for(int l=; l<F/D; l++)
{
int d=l*D;
if((a+b+c+d)>F||(c+d)>(a+b)/*E) break;
int tz=(c+d);
int tm=(a+b);
if(x*(tm+tz)<=tz*(y+x))
{
x=tz;
y=tm;
}
}
}
}
}
printf("%d %d",x+y,x);
return ;
}

D - Restoring Road Network


Time limit : 2sec / Memory limit : 256MB

Score : 500 points

Problem Statement

In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads. The following are known about the road network:

  • People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.
  • Different roads may have had different lengths, but all the lengths were positive integers.

Snuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom. He thought that it represented the shortest distances between the cities along the roads in the kingdom.

Determine whether there exists a road network such that for each u and v, the integer Au,v at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v. If such a network exist, find the shortest possible total length of the roads.

Constraints

  • 1≤N≤300
  • If ij1≤Ai,j=Aj,i≤109.
  • Ai,i=0

Inputs

Input is given from Standard Input in the following format:

N
A1,1 A1,2 A1,N
A2,1 A2,2 A2,N

AN,1 AN,2 AN,N

Outputs

If there exists no network that satisfies the condition, print -1. If it exists, print the shortest possible total length of the roads.


Sample Input 1

Copy
3
0 1 3
1 0 2
3 2 0

Sample Output 1

Copy
3

The network below satisfies the condition:

  • City 1 and City 2 is connected by a road of length 1.
  • City 2 and City 3 is connected by a road of length 2.
  • City 3 and City 1 is not connected by a road.

Sample Input 2

Copy
3
0 1 3
1 0 1
3 1 0

Sample Output 2

Copy
-1

As there is a path of length 1 from City 1 to City 2 and City 2 to City 3, there is a path of length 2 from City 1 to City 3. However, according to the table, the shortest distance between City 1 and City 3 must be 3.

Thus, we conclude that there exists no network that satisfies the condition.


Sample Input 3

Copy
5
0 21 18 11 28
21 0 13 10 26
18 13 0 23 13
11 10 23 0 17
28 26 13 17 0

Sample Output 3

Copy
82

Sample Input 4

Copy
3
0 1000000000 1000000000
1000000000 0 1000000000
1000000000 1000000000 0

Sample Output 4

Copy
3000000000

Floyd最短路啊,然后统计下就好的

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
ll sum;
int a[N][N],p[N][N];
int n;
int main()
{
cin>>n;
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
cin>>a[i][j],sum+=a[i][j];
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(a[i][k]+a[k][j]<a[i][j])
{
cout<<-;
return ;
}
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(a[i][k]+a[k][j]==a[i][j]&&i!=k&&k!=j&&i!=j)
p[i][j]=;
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
if(p[i][j])
sum-=a[i][j];
cout<<sum/;
return ;
}
 

E - Bichrome Tree


Time limit : 2sec / Memory limit : 256MB

Score : 700 points

Problem Statement

We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2≤iN) is Vertex Pi.

To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.

Snuke has a favorite integer sequence, X1,X2,…,XN, so he wants to allocate colors and weights so that the following condition is satisfied for all v.

  • The total weight of the vertices with the same color as v among the vertices contained in the subtree whose root is v, is Xv.

Here, the subtree whose root is v is the tree consisting of Vertex v and all of its descendants.

Determine whether it is possible to allocate colors and weights in this way.

Constraints

  • 1≤N≤1 000
  • 1≤Pii−1
  • 0≤Xi≤5 000

Inputs

Input is given from Standard Input in the following format:

N
P2 P3 PN
X1 X2 XN

Outputs

If it is possible to allocate colors and weights to the vertices so that the condition is satisfied, print POSSIBLE; otherwise, print IMPOSSIBLE.


Sample Input 1

Copy
3
1 1
4 3 2

Sample Output 1

Copy
POSSIBLE

For example, the following allocation satisfies the condition:

  • Set the color of Vertex 1 to white and its weight to 2.
  • Set the color of Vertex 2 to black and its weight to 3.
  • Set the color of Vertex 3 to white and its weight to 2.

There are also other possible allocations.


Sample Input 2

Copy
3
1 2
1 2 3

Sample Output 2

Copy
IMPOSSIBLE

If the same color is allocated to Vertex 2 and Vertex 3, Vertex 2 cannot be allocated a non-negative weight.

If different colors are allocated to Vertex 2 and 3, no matter which color is allocated to Vertex 1, it cannot be allocated a non-negative weight.

Thus, there exists no allocation of colors and weights that satisfies the condition.


Sample Input 3

Copy
8
1 1 1 3 4 5 5
4 1 6 2 2 1 3 3

Sample Output 3

Copy
POSSIBLE

Sample Input 4

Copy
1

0

Sample Output 4

Copy
POSSIBLE

以下是某个聚聚的做法,建图暴力dfs+bitset,这个bitset的操作我不是很明白啊

#include<bits/stdc++.h>
using namespace std;
const int N=,M=;
int i,j,k,n,m,En;
int h[N],fa[N],f[N],X[N];
bitset<M>g;
struct edge
{
int s,n;
} E[N];
void E_add(int x,int y)
{
E[++En].s=y;
E[En].n=h[x];
h[x]=En;
}
bool dfs(int x)
{
for(int k=h[x]; k; k=E[k].n)
if(!dfs(E[k].s))
return ;
g.reset();
g[]=;
int sum=;
for(int k=h[x]; k; k=E[k].n)
{
g=g<<X[E[k].s]|g<<f[E[k].s];
sum+=X[E[k].s]+f[E[k].s];
}
for(int i=X[x]; i>=; i--)
if(g[i])
{
f[x]=sum-i;
return ;
}
return ;
}
int main()
{
scanf("%d",&n);
for(i=; i<=n; i++)
scanf("%d",&fa[i]),E_add(fa[i],i);
for(i=; i<=n; i++)
scanf("%d",&X[i]);
puts(dfs()?"POSSIBLE":"IMPOSSIBLE");
return ;
}

AtCoder Regular Contest 083的更多相关文章

  1. AtCoder Regular Contest 083 E - Bichrome Tree

    题目传送门:https://arc083.contest.atcoder.jp/tasks/arc083_c 题目大意: 给定一棵树,你可以给这些点任意黑白染色,并且赋上权值,现给定一个序列\(X_i ...

  2. AtCoder Regular Contest 083 D: Restoring Road Network

    题意 有一张无向带权连通图(点数<=300),给出任意两点i,j之间的最短路长度dis[i][j].问是否存在一张这样的无向图.如果不存在输出-1.如果存在输出所有这样的无向图中边权和最小的一张 ...

  3. AtCoder Regular Contest 083 C: Sugar Water

    题意 给你一个空杯子,有4种操作: 操作1 加100a克的水 操作2 加100b克的水 操作3 加c克的糖 操作4 加d克的糖 糖的质量不能超过水的质量e/100 糖和水的总质量不能超过f 糖的质量不 ...

  4. [AtCoder Regular Contest 083] Bichrome Tree

    树形DP. 每个点有两个属性:黑色点的权值和,白色点权值和,一个知道另一个也一定知道. 因为只要子树的和它相等的点得权值和不超过x[u],u点的权值总能将其补齐. 设计状态f[u]表示以u为根的子树, ...

  5. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  6. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  7. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  8. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  9. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

随机推荐

  1. 【虚拟机-部署】通过 Powershell 来调整 ARM 模式下虚拟机的尺寸

    需求描述 在部署完 ARM 模式的虚拟机以后,可以通过 PowerShell 命令来调整虚拟机的尺寸,以下是通过 PowerShell 命令来调整 ARM 模式的虚拟机尺寸. Note 本文只限于 A ...

  2. Locust安装教程与使用

    Locust安装教程与使用官网地址:https://github.com/locustio/locust 如果是python3+以上的环境,需要下载locust项目源码进行安装 因Centos7.2环 ...

  3. setup命令

    setup——配置网络(centos) 命令所在路径:usr/bin/setup 示例1: # setup

  4. OpenLayers 3 的 图层控制控件

    openlayers3的control中没有提供默认的图层控制控件. 但是git上已经有造好的轮子,直接拿来用就可以了.地址 https://github.com/walkermatt/ol3-lay ...

  5. UI与数据分离 与 UI的演进

    解藕的好处:UI内部模块能够灵活的变化. MVC或者三层架构着重强调了数据.业务逻辑和UI的分离. (MVC中的C只是UI和业务逻辑模块间的一个中转组件,理论上应该是个轻模块.) 以前的关注的解藕技术 ...

  6. java基础——接口与抽象类的区别

    (1)首先接口和抽象类的设计目的就是不一样的.接口是对动作的抽象,而抽象类是对根源的抽象. (2)对于抽象类,一个类只能继承一个抽象类.但是一个类可以同时实现多个接口. (3)接口是公开的,里面不能有 ...

  7. 【前端_js】JavaScript知识点总结

    1.JavaScript的定义及特性 1.1.定义 javascript是运行在客户端的一种直译式脚本语言(程序在运行过程中逐行进行解释),它的解释器被称为JavaScript引擎,为浏览器的一部分. ...

  8. uvm transaction modeling

    1.what is transaction? network transactions tcp/ip wifi 3g/4g bus transactions amba-ahb/apb/axi pci/ ...

  9. java上传附件,批量下载附件(一)

    上传附件代码:借助commons-fileupload-1.2.jar package com.str; import java.io.BufferedInputStream;import java. ...

  10. 多线程辅助类之CountDownLatch(三)

    CountDownLatch信号灯是一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待.它可以实现多线程的同步互斥功能,和wait和notify方法实现功能类似,具体 ...