uva12186 Another Crisis

只是一道普通的树的dfs而已。关于求最少人数的式子:(k*T – 1)/100 + 1k*T/100不需要解释。一个-1一个+1则起到了手动ceiling的功能。因为整数除法是自动floor,所以+1就是将其变成ceiling。但如果整数除法得出的结果恰恰本身就是一个整数,那么+1将导致错误的结果。这时就需要在整数除法前,在被除数上减去一个比较小的正数(epsilon)(epsilon的大小和后面的+1没有关系),从而使后面的+1可以正常工作。epsilon要足够小,从而不影响整数除法的正确性,比如(101-e)/100+1,e应小于1,否则式子得数会错误的变为1。

//  Created by Chenhongwei in 2015.
//  Copyright (c) 2015 Chenhongwei. All rights reserved.

#include"iostream"
#include"cstdio"
#include"cstdlib"
#include"cstring"
#include"climits"
#include"queue"
#include"cmath"
#include"map"
#include"set"
#include"stack"
#include"vector"
#include"sstream"
#include"algorithm"
using namespace std;
typedef long long ll;
vector<int>son[100100];
int n,t;
int dp(int u)
{
	if(son[u].empty())
		return 1;
	int k=son[u].size();
	vector<int >d;
	for(int i=0;i<k;i++)
		d.push_back(dp(son[u][i]));
	sort(d.begin(),d.end());
	int c=(k*t-1)/100+1;
	int ans=0;
	for(int i=0;i<c;i++)
		ans+=d[i];
	return ans;
}
int main()
{	
	//ios::sync_with_stdio(false);
	// freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(cin>>n>>t&&n+t)
	{
		int tmp;
		for(int i=0;i<=n;i++)
			son[i].clear();
		for(int i=1;i<=n;i++)
		{
			cin>>tmp;
			son[tmp].push_back(i);
		}
		cout<<dp(0)<<endl;

	}
	return 0;
}



阅读更多

Cave Crisis

02-20

问题描述 :nnnR2D2 was exploring a tunnel when a cave-in suddenly occurred. Oh no, is he trapped?nnRobot Roll Call � Cambot…Servo…Gypsy…CroooownFigure1: Overhead view of the cave crisis from the third example test case.nnFrom an overhead view, we can see all the obstacles (debris) on a two-dimensional Cartesian plane. The tunnel is w cm wide, bounded by the lines y = w/2 and ny = -w/2. R2D2 starts at (0, 0), and has a perfectly circular footprint of radius r. The exit of the tunnel lies to the right of the line x = 1000. Between R2D2 and the exit lie a number of polygonal obstacles.nnnIs it possible for R2D2 to navigate between the obstacles and make it to the exit?nnnRobot Roll Call � Cambot…Servo…Gypsy…Croooown n输入:nnnThe input file will contain multiple test cases. Each test case begins with a single line containing an even integer w (2 <= w <= 1000), the width of the tunnel, and an integer N (0 <= N <= 100), the number of obstacles. The next N lines each contain the description of a single obstacle. The ith obstacle is a simple polygon, specified on a single line containing an integer ni (3 <= ni <= 10), the number of vertices, followed by ni pairs of integers, xij and yij (0 <= xij <= 1000 and -w/2 <= yij <= w/2 for j = 1, …, ni ), specifying the coordinates of the vertices in counterclockwise order. Note that obstacles in the input may touch or even overlap. However, you are guaranteed that R2D2’s initial location will not touch or overlap any obstacle. The vertices of each polygon are unique, no two nonconsecutive edges of the polygon intersect (even at their endpoints), and each polygon is guaranteed to have nonzero area. The end-of-input is denoted by an invalid test case with w = N = 0 and should not be processed. n输出:nnnThe input file will contain multiple test cases. Each test case begins with a single line containing an even integer w (2 <= w <= 1000), the width of the tunnel, and an integer N (0 <= N <= 100), the number of obstacles. The next N lines each contain the description of a single obstacle. The ith obstacle is a simple polygon, specified on a single line containing an integer ni (3 <= ni <= 10), the number of vertices, followed by ni pairs of integers, xij and yij (0 <= xij <= 1000 and -w/2 <= yij <= w/2 for j = 1, …, ni ), specifying the coordinates of the vertices in counterclockwise order. Note that obstacles in the input may touch or even overlap. However, you are guaranteed that R2D2’s initial location will not touch or overlap any obstacle. The vertices of each polygon are unique, no two nonconsecutive edges of the polygon intersect (even at their endpoints), and each polygon is guaranteed to have nonzero area. The end-of-input is denoted by an invalid test case with w = N = 0 and should not be processed.n样例输入:nn6 2n4 2 -1 4 -1 4 1 2 1n3 3 0 6 -1 6 1n8 2n3 1 -1 4 -1 4 4n3 3 -4 6 1 3 1n10 7n4 0 5 4 2 5 3 4 5n3 4 -5 9 -5 9 0n4 8 -5 11 -5 11 -2 8 -2n3 8 3 16 1 11 5n4 21 -5 23 -3 20 -2 15 -4n3 22 3 26 -1 28 0n3 24 0 29 4 25 3n0 0

another

10-01

[code=java]rn2013-10-1 22:16:38 org.apache.catalina.core.AprLifecycleListener initrn信息: Loaded Apache Tomcat Native library 1.1.10.rn2013-10-1 22:16:38 org.apache.catalina.core.AprLifecycleListener initrn信息: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].rn2013-10-1 22:16:40 org.apache.coyote.http11.Http11AprProtocol initrn信息: Initializing Coyote HTTP/1.1 on http-8080rn2013-10-1 22:16:40 org.apache.coyote.ajp.AjpAprProtocol initrn信息: Initializing Coyote AJP/1.3 on ajp-8009rn2013-10-1 22:16:40 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 2890 msrn2013-10-1 22:16:40 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2013-10-1 22:16:40 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/6.0.14rn2013-10-1 22:16:41 org.apache.catalina.core.ApplicationContext logrn信息: ContextListener: contextInitialized()rn2013-10-1 22:16:41 org.apache.catalina.core.ApplicationContext logrn信息: SessionListener: contextInitialized()rn2013-10-1 22:16:44 org.apache.catalina.core.ApplicationContext logrn信息: Initializing Spring root WebApplicationContextrnlog4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).rnlog4j:WARN Please initialize the log4j system properly.rn2013-10-1 22:17:07 org.apache.coyote.http11.Http11AprProtocol startrn信息: Starting Coyote HTTP/1.1 on http-8080rn2013-10-1 22:17:07 org.apache.coyote.ajp.AjpAprProtocol startrn信息: Starting Coyote AJP/1.3 on ajp-8009rn2013-10-1 22:17:07 org.apache.catalina.startup.Catalina startrn信息: Server startup in 27566 msrn0rnstrutsrn2013-10-01rnorg.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: update FacelookPhoto fp set fp.fpOrder=12 where fp.fpOrder=?; nested exception is org.hibernate.MappingException: Unknown entity: update FacelookPhoto fp set fp.fpOrder=12 where fp.fpOrder=?rn at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)rn at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)rn at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)rn at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:724)rn at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:718)rn at facelook.dao.impl.PhotoDaoImpl.updatePhoto(PhotoDaoImpl.java:24)rn at facelook.biz.impl.PhotoBizImpl.updatePhoto(PhotoBizImpl.java:33)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)rn at $Proxy6.updatePhoto(Unknown Source)rn at facelook.action.PhotoAction.photoUpload(PhotoAction.java:50)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:306)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn org.springframework.orm.hibernate3.HibernateTemplate$15.doInHibernate(HibernateTemplate.java:727)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)rn ... 84 morern[size=12px][/size]rn[/code]

没有更多推荐了,返回首页