浙大历年考研真题(1)

来源:互联网 发布:单片机郭天祥 百度云 编辑:程序博客网 时间:2024/04/28 22:01

题目链接:http://ac.jobdu.com/problem.php?pid=1010


题目1010:A + B

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:5629

解决:2928

题目描述:
读入两个小于100的正整数A和B,计算A+B.
需要注意的是:A和B的每一位数字由对应的英文单词给出.
输入:
测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.
输出:
对每个测试用例输出1行,即A+B的值.
样例输入:
one + two =three four + five six =zero seven + eight nine =zero + zero =
样例输出:
39096
来源:
2005年浙江大学计算机及软件工程研究生机试真题
解题思路:

        新技能·····字符串到整数的映射·······map<string , int>



完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI; string s[10] = { "zero" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine"}; map<string , int>Q; void init(){    for(int i = 0 ; i <= 9 ; i ++)        Q[s[i]] = i;}  int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    string str;    init();    while(getline(cin , str))    {        int a = 0 , b = 0 , flag = 0;        int len = str.length();        for(int i = 0 ; i < len ; i++)        {            string ch = "";            while(str[i] != ' ' && i < len)            {                ch += str[i];                i ++;            }            if(ch[0] == '+' || ch[0] == '=')            {                flag = 1;                continue;            }            if(!flag)                a = a * 10 + Q[ch];            else                b = b * 10 + Q[ch];        }        if(a == 0 && b == 0)            break;        else            cout << a + b << endl;    }}                  /**************************************************************    Problem: 1010    User: DoubleQ    Language: C++    Result: Accepted    Time:10 ms    Memory:1528 kb****************************************************************/






题目链接:http://ac.jobdu.com/problem.php?pid=1011


题目1011:最大连续子序列

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4448

解决:2137

题目描述:
    给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个,例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为{ 11, -4, 13 },最大和为20。现在增加一个要求,即还需要输出该子序列的第一个和最后一个元素。
输入:

    测试输入包含若干测试用例,每个测试用例占2行,第1行给出正整数K( K< 10000 ),第2行给出K个整数,中间用空格分隔。当K为0时,输入结束,该用例不被处理。

输出:

    对每个测试用例,在1行里输出最大和、最大连续子序列的第一个和最后一个元素,中间用空格分隔。如果最大连续子序列不唯一,则输出序号i和j最小的那个(如输入样例的第2、3组)。若所有K个元素都是负数,则定义其最大和为0,输出整个序列的首尾元素。

样例输入:
6-2 11 -4 13 -5 -210-10 1 2 3 4 -5 -23 3 7 -2165 -8 3 2 5 01103-1 -5 -23-1 0 -20
样例输出:
20 11 1310 1 410 3 510 10 100 -1 -20 0 0
来源:
2005年浙江大学计算机及软件工程研究生机试真题
解题思路:

       对数组进行O(n)的扫描,寻找最大连续子序列和,同时记录起始数和终止数。

       先说说O(n)的扫描······思想就是当从 s 加到 e 发现和小于0的时候,那么 s 到 e - 1 一定大于 0 ·····很好想····不用证明······回到正题,小于0的话把 s 更新成 e + 1 ,即下一次我们从 e + 1位置开始记录(比暴力那种方法时间复杂度降了好多)·······具体证明·····百度一下,你就知道······

       时间复杂度降下来了······但是这是你会发现样例结果出现了WA,比如-1 , 0 , -2这组数据,起始数和终止数应该都是0······这种情况下就在扫面前把序列里的最小数找出来,记录为key,扫描前让 s 和 e 都初值为key·······很不错·······



完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int a[100001];int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n;    while(~scanf("%d",&n) && n)    {        int flag = 0;        for(int i = 0 ; i < n ;i ++)        {            scanf("%d",&a[i]);            if(a[i] >= 0)                flag = 1;        }        if(flag == 0)        {            cout << "0" << " " << a[0] << " " << a[n-1] << endl;            continue;        }               /*int maxsum = 0 , thissum = 0;        int s = 0 , e = 0;        for(int i = 0 , j = 0 ; i < n ; i ++)        {            thissum += a[i];            e = a[i];            if(thissum < 0)            {                j = i + 1;                thissum = 0;            }             else if(thissum > maxsum)            {                maxsum = thissum;                s = j;                e = i;            }         }*/    int key = 0;    for(int i = 1 ; i < n ; i++)    {        if(a[key] < a[i])            key = i;    }     int maxSum = 0;    int thisSum = 0;    int seqEnd = key , seqStart = key;    for( int i = 0, j = 0; j < n; j++ )    {        thisSum += a[ j ];         if( thisSum > maxSum )        {            maxSum = thisSum;            seqStart = i;            seqEnd   = j;         }        else if( thisSum < 0 )        {            i = j + 1;            thisSum = 0;        }    }        cout << maxSum << " " << a[seqStart] << " " << a[seqEnd] << endl;    }} /**************************************************************    Problem: 1011    User: DoubleQ    Language: C++    Result: Accepted    Time:20 ms    Memory:1908 kb****************************************************************/






题目链接:http://ac.jobdu.com/problem.php?pid=1015



题目1015:还是A+B

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4980

解决:3002

题目描述:
读入两个小于10000的正整数A和B,计算A+B。需要注意的是:如果A和B的末尾K(不超过8)位数字相同,请直接输出-1。
输入:

测试输入包含若干测试用例,每个测试用例占一行,格式为"A B K",相邻两数字有一个空格间隔。当A和B同时为0时输入结束,相应的结果不要输出。

输出:

对每个测试用例输出1行,即A+B的值或者是-1。

样例输入:
1 2 111 21 1108 8 236 64 30 0 1
样例输出:
3-1-1100
来源:
2006年浙江大学计算机及软件工程研究生机试真题
解题思路:

      没什么好说的······测试它的服务器质量的题········      



完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI; int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int a , b , k;    while(~scanf("%d%d%d",&a,&b,&k))    {        int flag = 0;        int cnt1 = a , cnt2 = b;        if(a == 0 && b == 0)        {            break;        }        while(k -- && a && b)        {            int x = a % 10;            int y = b % 10;            if(x != y)            {                flag = 1;                break;            }            a = a / 10;            b = b / 10;        }        if(flag == 1)        {            cout << a + b << endl;            continue;        }        else            cout << "-1" << endl;    }} /**************************************************************    Problem: 1015    User: DoubleQ    Language: C++    Result: Accepted    Time:0 ms    Memory:1520 kb****************************************************************/





题目链接:http://ac.jobdu.com/problem.php?pid=1016



题目1016:火星A+B

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4117

解决:1122

题目描述:
    读入两个不超过25位的火星正整数A和B,计算A+B。需要注意的是:在火星上,整数不是单一进制的,第n位的进制就是第n个素数。例如:地球上的10进制数2,在火星上记为“1,0”,因为火星个位数是2进制的;地球上的10进制数38,在火星上记为“1,1,1,0”,因为火星个位数是2进制的,十位数是3进制的,百位数是5进制的,千位数是7进制的……
输入:
    测试输入包含若干测试用例,每个测试用例占一行,包含两个火星正整数A和B,火星整数的相邻两位数用逗号分隔,A和B之间有一个空格间隔。当A或B为0时输入结束,相应的结果不要输出。
输出:
    对每个测试用例输出1行,即火星表示法的A+B的值。
样例输入:
1,0 2,14,2,0 1,2,01 10,6,4,2,10 0
样例输出:
1,0,11,1,1,01,0,0,0,0,0
来源:
2006年浙江大学计算机及软件工程研究生机试真题
解题思路:

        刚开始下手感觉有点类似于大数加法·····把两个数整理下然后逆置(逆置后方便进位),它和大数加法的不同之处是,大数加法满十进一,但它的每位根据对应的素数而定,满该位素数进一

       写的微暴力······WA了几次后····左改右改·····左添右添·····就AC了······



完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;string a , b;const int maxn = 501;int aa[maxn] , bb[maxn] , c[maxn];int pri[maxn];bool ispri[10001];    void dopri(){    memset(ispri , 1 , sizeof(ispri));    int t = 0;    for(int i = 2 ; i <= 10001 ; i ++)    {        if(ispri[i])        {            pri[t++] = i;            for(int j = i * 2 ; j <= 10001 ; j += i)                ispri[j] = false;        }    }}  int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    dopri();    while(cin >> a >> b)    {         memset(aa , 0 , sizeof(aa));        memset(bb , 0 , sizeof(bb));        memset(c , 0 , sizeof(c));        int lena = a.length();        int lenb = b.length();        if(a == "0" || b == "0")            break;        int ta = 0;        int result = 0;         for(int i = 0 ; i < lena ; i ++)        {            if(a[i] == ',')            {                aa[ta++] = result;                result = 0;             }             else            {                result = result * 10 + (a[i] - '0');            }         }         aa[ta++] = result;        int k;        for(int i = 0 , j = ta - 1 ; i < j ; i ++ , j--)        {            k = aa[i];            aa[i] = aa[j];            aa[j] = k;        } /*        for(int i = 0 ; i < ta ; i ++)            cout << aa[i] << " ";            cout << endl;*/         int tb = 0;        int result2 = 0;         for(int i = 0 ; i < lenb ; i ++)        {            if(b[i] == ',')            {                bb[tb++] = result2;                result2 = 0;             }            else            {                 result2 = result2 * 10 + (b[i] - '0');            }        }         bb[tb++] = result2;        for(int i = 0 , j = tb - 1 ; i < j ; i ++ , j --)        {            k = bb[i];            bb[i] = bb[j];            bb[j] = k;        }/*        for(int i = 0 ; i < tb ; i ++)            cout << bb[i] << " ";            cout << endl;*/          int key = 0;        for(int i = 0 ; i < maxn ; i ++)        {            int cnt = aa[i] + bb[i] + key;           // if(i < 10)          //      cout << cnt << " " ;            if(cnt >= pri[i])            {                c[i] = cnt - pri[i] * (cnt / pri[i]);                key = cnt / pri[i];            }            else            {                 c[i] = cnt;                key = 0;            }          }       // cout << endl;        //cout << "hello" << endl;        int i = maxn - 1;        while(!c[i])            i--;         for(int j = i ; j >= 1 ; j --)            cout << c[j] << ",";        cout << c[0] << endl;    }} /**************************************************************    Problem: 1016    User: DoubleQ    Language: C++    Result: Accepted    Time:10 ms    Memory:1536 kb****************************************************************/





题目链接:http://ac.jobdu.com/problem.php?pid=1018



题目1018:统计同成绩学生人数

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:6006

解决:3245

题目描述:
读入N名学生的成绩,将获得某一给定分数的学生人数输出。
输入:
测试输入包含若干测试用例,每个测试用例的格式为


第1行:N
第2行:N名学生的成绩,相邻两数字用一个空格间隔。
第3行:给定分数

当读到N=0时输入结束。其中N不超过1000,成绩分数为(包含)0到100之间的一个整数。
输出:
对每个测试用例,将获得给定分数的学生人数输出。
样例输入:
380 60 9060285 660560 75 90 55 75750
样例输出:
102
来源:
2006年浙江大学计算机及软件工程研究生机试真题
解题思路:

         测服务器质量的······不解释·····


完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int vis[101];int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif    int n;    while(~scanf("%d",&n) && n)    {        int k;        memset(vis , 0  ,  sizeof(vis));        for(int i = 0 ; i < n ; i++)        {            scanf("%d",&k);            vis[k] ++;        }        int t;        scanf("%d",&t);        cout << vis[t] << endl;    }} /**************************************************************    Problem: 1018    User: DoubleQ    Language: C++    Result: Accepted    Time:10 ms    Memory:1520 kb****************************************************************/





题目链接:http://ac.jobdu.com/problem.php?pid=1020



题目1020:最小长方形

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:4986

解决:2385

题目描述:
    给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内。长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内。
输入:

    测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231;一对0 坐标标志着一个测试用例的结束。注意(0, 0)不作为任何一个测试用例里面的点。一个没有点的测试用例标志着整个输入的结束。

输出:

    对每个测试用例,在1行内输出2对整数,其间用一个空格隔开。第1对整数是长方形框左下角的坐标,第2对整数是长方形框右上角的坐标。

样例输入:
12 5623 5613 100 012 340 00 0
样例输出:
12 10 23 5612 34 12 34
来源:
2007年浙江大学计算机及软件工程研究生机试真题
解题思路:

       求出min_x , min_y , max_x , max_y就AC了······



完整代码:

#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL; /** Constant List .. **/ //{ const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int a[1001] , b[1001];int main(){    #ifdef DoubleQ    freopen("in.txt","r",stdin);    #endif     while(~scanf("%d%d",&a[0],&b[0]))    {        if(a[0] == 0 && b[0] == 0)            break;        int i = 1;        while(scanf("%d%d",&a[i],&b[i]))        {            if(a[i] == 0 && b[i] == 0)                break;            i++;        }        int max_x = a[0] , min_x = a[0];        for(int j = 0 ; j < i ; j ++)        {            if(a[j] > max_x)                max_x = a[j];            if(a[j] < min_x)                min_x = a[j];        }        int max_y = b[0] , min_y = b[0];        for(int j = 0 ; j < i ; j ++)        {            if(b[j] > max_y)                max_y = b[j];            if(b[j] < min_y)                min_y = b[j];        }        cout << min_x << " " << min_y << " " << max_x << " " << max_y << endl;    }}                          /**************************************************************    Problem: 1020    User: DoubleQ    Language: C++    Result: Accepted    Time:0 ms    Memory:1528 kb****************************************************************/







0 0
原创粉丝点击