codeforces 722C Destroying Array

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq_36542637/article/details/79979263

题意:给出长度为n的序列,每次去掉一个数,使得序列分成几块,问当前权值最大块的权值。
思路:提供两种,第一种用multiset和前缀和直接暴力模拟。
第二种用并差集,假设坐标i为一个去掉的数,那么f[i]记录的是i所在连续的去掉的数的区间的最左端,其余的看代码QAQ。

第一种
#include<bits/stdc++.h>
using namespace std;
long long   a[100001], t[100001];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i], t[i] = t[i - 1] + a[i];
    multiset<long long>s {0, n + 1}, q {t[n]};
    for(int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        auto j = s.insert(p), k = j, l = j;
        q.erase(q.find(t[*++l - 1] - t[*--k]));
        q.insert(t[*j - 1] - t[*k]);
        q.insert(t[*l - 1] - t[*j]);
        cout << *--q.end() << endl;
    }
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
int b[100005], f[100005];
long long a[100005], ans[100005];
int find(int x) {
    return f[x] == x ? x : f[x] = find(f[x]);
}
int main() {
    int n;
    scanf("%d\n", &n);
    for (int i = 1; i <= n; i++)
        scanf("%I64d", &a[i]);
    for (int i = 1; i <= n; i++)
        scanf("%d", &b[i]);
    ans[n] = 0;
    for (int i = n; i > 1; i--) {
        int x = b[i];
        f[x] = x;
        if (f[x + 1])
            a[f[x + 1] = x] += a[x + 1];
        if (f[x - 1])
            a[f[x] = find(x - 1)] += a[x];
        ans[i - 1] = max(ans[i], a[find(x)]);
    }
    for (int i = 1; i <= n; i++)
        printf("%I64d\n", ans[i]);
}

:Destroying singletons in org.springframework.beans.factory.support.DefaultLista

12-22

2016-12-22 22:43:48,640 [INFO ][org.springframework.cache.ehcache.EhCacheManagerFactoryBean]:Initializing EhCache CacheManagerrn[color=#FF0000]2016-12-22 22:43:50,307 [INFO ][org.springframework.beans.factory.support.DefaultListableBeanFactory]:Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@56f9659d:[/color] defining beans [mvcContentNegotiationManager,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerM[color=#FF0000]一堆bean的全限定名.[/color]Error: Unresolved compilation problem: rn String literal is not properly closed by a double-quoternrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)rn at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)rn at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)rn at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)rn at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)rn at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)rn at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)rn at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)rn at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)rn at javax.servlet.GenericServlet.init(GenericServlet.java:212)rn at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1213)rn at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)rn at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)rn at org.apache.catalina.core.StandardService.start(StandardService.java:525)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:595)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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)rnCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dcits.tmock.service.switchmode.IModeService com.dcits.tmock.controller.AdminController.modeService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'modeService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dcits.tmock.util.cache.SystemCacheService com.dcits.tmock.service.switchmode.ModeServiceImpl.cacheService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheService' defined in ServletContext resource [/WEB-INF/service-context.xml]: Invocation of init method failed; nested exception is java.lang.Error: Unresolved compilation problem: rn String literal is not properly closed by a double-quoternrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)rn at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)rn ... 43 morernCaused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'modeService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dcits.tmock.util.cache.SystemCacheService com.dcits.tmock.service.switchmode.ModeServiceImpl.cacheService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheService' defined in ServletContext resource [/WEB-INF/service-context.xml]: Invocation of init method failed; nested exception is java.lang.Error: Unresolved compilation problem: rn String literal is not properly closed by a double-quoternrn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)rn at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)rn at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)rn at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)rn at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)rn at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:910)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:853)rn at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)rn at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)rn ... 45 morernCaused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dcits.tmock.util.cache.SystemCacheService com.dcits.tmock.service.switchmode.ModeServiceImpl.cacheService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheService' defined in ServletContext resource [/WEB-INF/service-context.xml]: Invocation of init method failed; nested exception is java.lang.Error: Unresolved compilation problem: rn String literal is not properly closed by a double-quoternrnrnrnrn

codeforces 621B wrong answer 求解

02-03

题目rnrnB. Wet Shark and Bishopsrnrntime limit per test:2 secondsrnrnmemory limit per test:256 megabytesrnrninput:standard inputrnrnoutput:standard outputrnrnrnToday, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.rnrnWet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the only criteria, so two bishops may attack each other (according to Wet Shark) even if there is another bishop located between them. Now Wet Shark wants to count the number of pairs of bishops that attack each other.rnrnrnInputrnrnThe first line of the input contains n (1 ≤ n ≤ 200 000) — the number of bishops.rnrnEach of next n lines contains two space separated integers xi and yi (1 ≤ xi, yi ≤ 1000) — the number of row and the number of column where i-th bishop is positioned. It's guaranteed that no two bishops share the same position.rnrnrnOutputrnrnOutput one integer — the number of pairs of bishops which attack each other. rnrnrnSample test(s)rnrnrnrnInputrn5rn1 1rn1 5rn3 3rn5 1rn5 5rnrnrnrnOutputrn6rnrnrnrnInputrn3rn1 1rn2 3rn3 5rnrnrnrnOutputrn0rnrnrnrnNoternrnIn the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.rnrnrnrnrn我的代码rn#includern#includern#includern#includern#includern#includern#includernusing namespace std;rnint x[1050],y[1050],n,a[1050][1050];rnbool panduan(int i,int j)rnrn if((i>=1)&&(i<=1000)&&(j>=1)&&(j<=1000))rn return true;rn elsern return false;rnrnint main(void)rnrn long long sum=0;rn int ii,jj,status,j,i,temp_a,temp_b;rn scanf("%d",&n);rn for(i=1;i<=1000;i++)rn for(j=1;j<=1000;j++)rn a[i][j]=0;rn for(i=0;i

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

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试