博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AtCoder Regular Contest 083
阅读量:6214 次
发布时间:2019-06-21

本文共 8648 字,大约阅读时间需要 28 分钟。

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
int main(){ int A,B,C,D,E,F,x=1,y=1; scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F); for(int i=0; i<=F/(100*A); i++) { int a=i*100*A; if(a>F) break; for(int j=0; j<=F/(100*B); j++) { int b=j*100*B; if(a+b>F) break; for(int k=0; k
F) break; for(int l=0; l
F||(c+d)>(a+b)/100*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 0;}

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:

NA1,1 A1,2 … A1,NA2,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
30 1 31 0 23 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
30 1 31 0 13 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
50 21 18 11 2821 0 13 10 2618 13 0 23 1311 10 23 0 1728 26 13 17 0

Sample Output 3

Copy
82

Sample Input 4

Copy
30 1000000000 10000000001000000000 0 10000000001000000000 1000000000 0

Sample Output 4

Copy
3000000000

 


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

#include
using namespace std;typedef long long ll;const int N=305;ll sum;int a[N][N],p[N][N];int n;int main(){ cin>>n; for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) cin>>a[i][j],sum+=a[i][j]; for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) if(a[i][k]+a[k][j]

 

 

 

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:

NP2 P3 … PNX1 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
31 14 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
31 21 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
81 1 1 3 4 5 54 1 6 2 2 1 3 3

Sample Output 3

Copy
POSSIBLE

Sample Input 4

Copy
10

Sample Output 4

Copy
POSSIBLE

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

#include
using namespace std;const int N=1010,M=5050;int i,j,k,n,m,En;int h[N],fa[N],f[N],X[N];bitset
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 0; g.reset(); g[0]=1; int sum=0; for(int k=h[x]; k; k=E[k].n) { g=g<
<
=0; i--) if(g[i]) { f[x]=sum-i; return 1; } return 0;}int main(){ scanf("%d",&n); for(i=2; i<=n; i++) scanf("%d",&fa[i]),E_add(fa[i],i); for(i=1; i<=n; i++) scanf("%d",&X[i]); puts(dfs(1)?"POSSIBLE":"IMPOSSIBLE"); return 0;}

 

转载于:https://www.cnblogs.com/BobHuang/p/7610978.html

你可能感兴趣的文章
python全栈_003_Python3运算符
查看>>
新maven项目创建JSP出现小红叉报错 javax.servlet.http.HttpServlet not found
查看>>
微信小程序列表加载更多
查看>>
leetcode笔记-1 twosum
查看>>
深浅拷贝
查看>>
sql查询重复记录、删除重复记录方法大全
查看>>
odoo开发笔记 -- 用户配置界面增加模块访问权限
查看>>
instanceof函数内部机制探析
查看>>
linux下phpstorm的快速安装
查看>>
批量删除和批量修改(参数使用list)
查看>>
前端通用框架可行性研究报告之弹窗
查看>>
数据转换
查看>>
IOS在一个程序中启动另一个程序
查看>>
Dubbo初探
查看>>
CDI Features
查看>>
Linux中安装Oracle jdk
查看>>
MFC界面伸缩
查看>>
笔记本搜不到路由无线信号
查看>>
动态规划算法学习总结
查看>>
java 24小时倒计时案例
查看>>