A Count Task

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u013345179/article/details/90738926

A Count Task

Count is one of WNJXYK’s favorite tasks. Recently, he had a very long string and he wondered that how many substrings which contains exactly one kind of lowercase in this long string. But this string is so long that he had kept counting for several days. His friend Kayaking wants to help him, so he turns to you for help.
Input
The input starts with one line contains exactly one positive integer TT which is the number of test cases.
Each test case contains one line with a string which you need to do a counting task on.
Output
For each test case, output one line containing “y” where y is the number of target substrings.
Sample Input
3
qwertyuiop
qqwweerrttyyuuiioopp
aaaaaaaaaa
Sample Output
10
30
55
Hint
1<=T<=20,1<=len(string)<=105,1<=∑len(string)<=105
Strings only contain lowercase English letters.

题意大概就是现有一串全为小写字母的字符串求其中字串只含一种小写字母的所有情况。
思路,从前往后暴力因为只含一种字母所以我们只需要寻找最长的连续相同的字母设其长为l那么这一子段字串的个数就是(l+1)*l/2;就是以1为首项1为公差的等差序列的和(eg,长度为l的串有一个 长度为l-1的串有2个类推到长度为1的字串有l个)。还需要注意要用longlong
ac

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int v[20089],s[2],m;
int dp[20089][50];
int main(){
    long long int n,s,sum;
    char x;
    string a;
    cin>>n;
    while(n--)
    {
        s=0,sum=0;
        cin>>a;
        a+='0';
        x=a[0];
        for(int i=0;i<a.size();i++)
        {
            if(a[i]==x)
            {
                s++;
            }
            else
            {
                sum+=s*(s+1)/2;
                x=a[i];
                s=1;
            }
        }
        cout<<sum<<endl;
    }
}
展开阅读全文

Carrying Out A Task

11-03

Problem DescriptionnDuring the process of the military exercise, there is a ship on the sea level .The ship will go to certain place to carry out a task. For every action, the ship has two ways to sail. They are normal sailing and accelerated sailing. The normal speed of the ship is certain, when the ship sails normally, it can only move 1 step to the adjacent normal sea level. The ship can also accelerate. There are 2 kinds of accelerated sailings, one is moving forward d steps (d <= 5) in a straight line, and it must move forward d steps exactly every time it accelerates, The d steps must be on the normal sea level, otherwise, it can not accelerate. The other is accelerating while getting through the undercurrent. There are a lot of undercurrents on the sea, and entering the undercurrent area needs to accelerate when the ship is 1 step to the undercurrent. However, the ship itself will be damaged more or less by the undercurrent, After entering the undercurrent, the speed of the ship will become normal immediately. Every time it accelerates, the ship has to consume a certain B energy, and when it starts up ,it carries certain B energy. nnWhile the ship is sailing on the sea, it needs to consume a certain A energy. One unit of distance will consume one unit of A energy, and when the ship starts up, it carries enough A energy. nnThere are many reefs on the sea, and the ship can not get through.nnNow the ship is required to sail to the certain place, of course, to minimize the damage to the ship itself is a priority because the cost of ships is very expensive. The damage is, of course, the smaller, the better. At the same time, an attempt should be made to control the consumption of A energy to the smallest amount during the whole process because the cost of A energy is much more expensive than that of B energy, and you can use B energy which the ship carried when it started up as you wish. nnNow the question is to work out the minimal times of action from the departure point to the destination under the condition that to minimize the damage to the ship is a priority and then the consumption of A energy to the smallest degree. nn n nnInputnThe input file contains several test cases, the first line contains an integer T, indicates the number of test cases. In each case the first line includes two integers n, m (5 <= n, m <= 20), which indicate the size of the sea level for military exercises, and n rows and m columns are the current state of the sea level ('S' indicates the ship's initial position, 'E' indicates the destination place, '#' indicates the reefs, '*' indicates the undercurrent , ' ' the normal sea level), followed a line with a number d in it, it indicates the distance of the first kind of acceleration, then another line includes two integers, indicate that the initial value of the B energy and the value of the B energy needed while accelerating every time.n nnOutputnOutput an integer to indicate the smallest times of action, and if can not reach the task place, then output "can not reach!"n nnSample Inputn2n5 10n##########n#E #n#*###### #n#S #n##########n5n10 2n6 10n##########n#E #n#*######*#n#*######*#n#S #n##########n5n3 2n nnSample Outputn8ncan not reach! 问答

Count(*) 和 count(1) 的问题

05-31

为什么我用List result = _dao.find("SELECT COUNT(*) AS count from DrawingnoMap A");不会报错,rn而当我写成 List result = _dao.find("SELECT COUNT(1) AS count from DrawingnoMap A");就会报下面的异常:rnException in thread "Thread-6" java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)Vrnrn at org.hibernate.hql.antlr.HqlBaseParser.aggregate(HqlBaseParser.java:4421)rnrn at org.hibernate.hql.antlr.HqlBaseParser.identPrimary(HqlBaseParser.java:4052)rnrn at org.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:861)rnrn at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3438)rnrn at org.hibernate.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3216)17:18:07,531 ERROR PARSER[reportError]:33 - line 1:14: unexpected token: 1rnrn at org.hibernate.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3098)rnrn at org.hibernate.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2818)rnrn at org.hibernate.hql.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:570)rnrn at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2586)rnrn at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)rnrn at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)rnrn at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)rnrn at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)rnrn at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)rnrn at org.hibernate.hql.antlr.HqlBaseParser.aliasedExpression(HqlBaseParser.java:2249)rnrn at org.hibernate.hql.antlr.HqlBaseParser.selectedPropertiesList(HqlBaseParser.java:1455)rnrn at org.hibernate.hql.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:1365)rnrn at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1106)rnrn at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)rnrn at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)rnrn at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)rnrn at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:248)rnrn at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)rnrn at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)rnrn at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:77)rnrn at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:56)rnrn at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)rnrn at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)rnrn at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)rnrn at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)rnrn at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:832)rnrn at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)rnrn at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:830)rnrn at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:822)rnrn at org.ejs.dao.support.GenericDaoSupport.find(Unknown Source)rnrn at com.application.dao.hibernate.HibernateDrawingnoMapDAO.findByDrawingnoCode(HibernateDrawingnoMapDAO.java:34)rnrn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rnrn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rnrn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rnrn at java.lang.reflect.Method.invoke(Method.java:585)rnrn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:280)rnrn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)rnrn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)rnrn at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:104)rnrn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)rnrn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)rnrn at $Proxy118.findByDrawingnoCode(Unknown Source)rnrn at com.application.service.pojo.POJODrawingnoMapService.findByDrawingnoCode(POJODrawingnoMapService.java:80)rnrn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rnrn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rnrn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rnrn at java.lang.reflect.Method.invoke(Method.java:585)rnrn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:280)rnrn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)rnrn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)rnrn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)rnrn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)rnrn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)rnrn at $Proxy119.findByDrawingnoCode(Unknown Source)rnrn at com.application.swing.business.DrawingnoMapPlugin.doRefresh(DrawingnoMapPlugin.java:304)rnrn at com.application.swing.business.DrawingnoMapPlugin.doStart(DrawingnoMapPlugin.java:298)rnrn at com.application.swing.MainFrame$1.run(MainFrame.java:176)rnrn at java.lang.Thread.run(Thread.java:595)rn我很纳闷,难道是hibernate 不支持count(1)???rnrn 论坛

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