浙大历年考研真题(1)
来源:互联网 发布:单片机郭天祥 百度云 编辑:程序博客网 时间:2024/04/28 22:01
题目链接:http://ac.jobdu.com/problem.php?pid=1010
新技能·····字符串到整数的映射·······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
对数组进行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
没什么好说的······测试它的服务器质量的题········
完整代码:
#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
刚开始下手感觉有点类似于大数加法·····把两个数整理下然后逆置(逆置后方便进位),它和大数加法的不同之处是,大数加法满十进一,但它的每位根据对应的素数而定,满该位素数进一
写的微暴力······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
测服务器质量的······不解释·····
完整代码:
#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
求出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****************************************************************/
- 浙大历年考研真题(1)
- 历年考研英语真题 mp3 下载
- 九度考研真题 浙大 2005-1浙大1013:开门人和关门人 排序
- 九度考研真题 浙大 2006-1浙大1015:还是A+B 比较
- 九度考研真题 浙大 2007-1浙大 题目1021:统计字符 字符串输入
- 九度考研真题 浙大 2009-1浙大1031:xxx定律
- 九度考研真题 浙大 2010-1浙大1003:A+B
- 九度考研真题 浙大 2011-1浙大1001:A+B for Matrices
- 九度考研真题 浙大 2012-1浙大1464:Hello World for U
- 《西方经济学》历年考研真题考点及重难点分析
- 东北大学考研线性表相关历年真题题目整理
- GIS历年考研题(名词解释)答案
- 九度考研真题 浙大 2005-2浙大1014:排名 多重排序
- 九度考研真题 浙大 2005-3浙大1012:畅通工程
- 九度考研真题 浙大 2006-2浙大 统计同成绩人数 hash
- 九度考研真题 浙大 2006-3浙大 简单计算器 堆操作
- 九度考研真题 浙大 2007-2浙大 题目1020:最小长方形 取最大最小值
- 九度考研真题 浙大 2007-3浙大游船出租 结构体
- 的方式的方式的发生地方
- 士大夫士大夫士大夫士大夫
- 学习敏捷开发(trello)之party_bid卡片3,4总结
- 显示进度条
- Codeforces Round #266 (Div. 2) A. Cheap Travel
- 浙大历年考研真题(1)
- lucene.net文件目录管理Directory类
- 在工作中一时不想干活怎么办
- 设计模式之-迭代器(Iterator pattern)
- jsp url重写办法
- vim快捷键小结
- win 8/plsql 连接 64位 oracle Client
- cocos2d-x创建一个场景
- POJ - 2406 Power Strings (KMP循环节)