码迷,mamicode.com
首页 > 其他好文 > 详细

2000年清华大学计算机研究生机试真题

时间:2015-04-05 16:06:56      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

题目连接:点击打开链接


解题思路:

不可以用cin,会超时

完整代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int INF = 1000000000;
const int maxn = 10001;
 char s[maxn];
int main()
{
   #ifdef DoubleQ
   freopen("in.txt" , "r" , stdin);
   #endif // DoubleQ
 
   while(~scanf("%s" , s))
   {
        int len = strlen(s);
        for(int i = len - 1 ; i >= 0 ; i --)
            printf("%c",s[i]);
        printf("\n");
   }
}

题目连接:点击打开链接


解题思路:

暴力枚举

完整代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int INF = 1000000000;
const int maxn = 10001;
 char s[maxn];
int main()
{/*
   #ifdef DoubleQ
   freopen("in.txt" , "r" , stdin);
   #endif // DoubleQ
   */ for(int i = 0 ; i <= 9 ; i ++)
    {
        for(int j = 0 ; j <= 9 ; j ++)
        {
            for(int k = 0 ; k <= 9 ; k ++)
            {
                int a = i * 100 + j * 10 + k;
                int b = j * 100 + k * 10 + k;
                if(a + b == 532)
                {
                    cout << i << " " << j << " " << k << endl;
                }
            }
        }
    }
}

题目连接:点击打开链接


解题思路:

枚举

完整代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int INF = 1000000000;
const int maxn = 10001;
int a[101] , b[101];
 
int check(int key)
{
    int sum = 0;
    for(int i = 1 ; i < key ; i ++)
    {
        if(key % i == 0)
            sum += i;
    }
    if(sum == key)  return 1;
    else if(sum > key)    return 2;
    else return 0;
}
 
 
int main()
{/*
   #ifdef DoubleQ
   freopen("in.txt" , "r" , stdin);
   #endif // DoubleQ
   */
   int cnt1 = 0 , cnt2 = 0;
   for(int i = 2 ; i <= 60 ; i ++)
   {
        if(check(i) == 1)
        {
            a[cnt1++] = i;
        }
        else if(check(i) == 2)
            b[cnt2++] = i;
   }
   cout << "E: ";
   for(int i = 0 ; i < cnt1 ; i ++)
        printf("%d%s" , a[i] , i == cnt1 - 1 ? "\n" : " ");
    cout << "G: ";
    for(int i = 0 ; i < cnt2 ; i ++)
        printf("%d%s" , b[i] , i == cnt2 - 1 ? "\n" : " ");
}

题目连接:点击打开链接


解题思路:

排序

完整代码:

#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;
 
struct node
{
    string s;
    int old;
    int score;
}q[1000001];
 
bool cmp(node a , node b)
{
    if(a.score != b.score)
        return a.score > b.score;
    else if(a.s != b.s)
        return a.s > b.s;
    else
        return a.old > b.old;
}
 
 
int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 0 ; i < n ; i ++)
        {
            cin >> q[i].s;
            scanf("%d%d",&q[i].old ,&q[i].score);
        }
        sort(q ,  q + n , cmp);
        for(int i = n - 1 ; i >= 0 ; i --)
        {
            cout << q[i].s << " " << q[i].old << " " << q[i].score << endl;
        }
    }
}


2000年清华大学计算机研究生机试真题

标签:

原文地址:http://blog.csdn.net/u013447865/article/details/44887851

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!