"科林明伦杯"哈尔滨理工大学第六届程序设计团队赛总结

3 篇文章 0 订阅

C.ID

Time Limit: 1000 MS Memory Limit: 1000000 K
Total Submit: 1421 (405 users) Total Accepted: 264 (247 users) Special Judge: No
Description
It is very cold in Harbin in the winter, but it is pretty warm in the Zhengxin Building. Today is Saturday, Teacher ABG want to play a trick on the only one student called NWL because he didn’t finish the MOOC.
At the beginning, every student is in the building. The teacher calls some students to sweep the snow on the playground out of the building, and sometimes he also call some students who are on the playground back to the building. At last, teacher ABG wants to leave only one student, NWL, on the playground out of the building. It means that the teacher ABG calls NWL’s ID ODD times, but called other students’ ID EVEN times, maybe more than twice. Now give you the list describing the students’ ID which the teacher called in order, please tell us NWL’s ID.
Input
The first line is an integer T, describes the number of tests. Then T tests.
In each test, the first line is an integer N, describes the number of IDs on the list.
Then followed N lines, each line contains an integer M, describes one ID on the list.
Output
T lines. Each line, an integer, the NWL’s ID.
Sample Input
3
3
1140310000
1140310000
1140310000
1
1140310002
5
1
2
2
2
2
Sample Output
1140310000
1140310002
1
Hint
1<=T<=10
1<=N<=1,000,000
1<=M<=1,159,999,999

The sum of N in the input file is no more than 3,000,000, all the input are integers and correct.

法一:根据异或运算的性质1: a^a=0, 2:a^a^a=a,偶数个=0,奇数个=本身。

#include <stdio.h>
int main ()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,a,ans=0;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&a);
            ans^=a;
        }
        printf("%d\n",ans);

    }
    return 0;
}
法二:用map解决


#include <stdio.h>
#include <map>
using namespace std;
int main ()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,a;
        map<int ,int>m;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d",&a);
            m[a]++;
        }
        map<int,int>::iterator it;
        for (it=m.begin(); it!=m.end(); it++)
            if(it->second&1==1)
            {
                printf("%d\n",it->first);
                break;
            }
    }
}

D.Game
Time Limit: 1000 MSMemory Limit: 100000 K
Total Submit: 498 (184 users)Total Accepted: 141 (137 users)Special Judge: No
Description

Kim is a college student who love computer games, but unfortunately his school just published a rule that Games should disappear in the campus , that means nobody can play computer games in school, including the students dormitory. However, the student don’t take it seriously, that’s why the manager of the school gets so angry that he decided to Go to the dormitory to punish the students. You should know the manager will punish those students who is playing games at the moment he enter the room, and leave immediately if nobody is playing game in this room.

  Kim is a talented game player , in fact, he is the Carry of a famous Gaming club, so he needs time to practice he’s skills . And luckily , Kim’s roommate Mik is a Geek(also a Kim fan), he hacked the manager’s computer and get the timetable of the manager, and tell Kim when will the manager come to their room tomorrow. A big E-sport Event is around the corner, so Kim list m skills he should practice, each skill takes some time to practice and improve Kim’s skill by some points. You should calculate the max total improvement points Kim can get. Note any skills can be practiced any times , including 0.

Input


The first line contains a integer T ( T <= 10 ), then T cases follows.

In each case, there are 3 parts of input. 

The first part contains 3 integers L, n, m in a single line.Range[0, L] is the time Kim decide to practice , n is the times manager would enter his room, m indicate the total number of the skills. 

The second part contains n integers ti(0 <= ti <= L) in a single line, means the manager would enter his room at ti. Note that ti is giving in the increasing order. 

The third part has m lines , each line contains two integers ci, vi, means this skill needs ci minutes to practice and can make vi points improvement.

L<=500, n<=10, m<=100.


Output

For each case, you should output the max points Kim can improve.

Sample Input
2
6 1 3
3
2 3
2 4
2 5
6 2 3
2 4
2 3
2 4
2 5
Sample Output
10
15
Hint

Note that Kim will be catch playing games any time in the interval of his practicing, excluded the beginning and the ending of each practice time. 

Sample 1:

D.Game sample 1

Sample 2:

D.Game sample 2


题解:多区间完全背包;

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
 int w[101],v[101];
 int dp[501];
 int DP(int l,int m)
 {
     memset(dp,0,sizeof(dp));
     for (int i=0;i<m;i++)
         for (int j=w[i];j<=l;j++)
             dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    return dp[l];
 }

int main ()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int l,n,m;
        scanf("%d%d%d",&l,&n,&m);
        int a[12];
        a[0]=0;
        a[n+1]=l;
        for (int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        for (int i=0;i<m;i++)
            scanf("%d%d",&w[i],&v[i]);
        int s=0;
        for (int i=0;i<=n;i++)
        {
            int L=a[i+1]-a[i];
            s+=DP(L,m);
        }
        printf("%d\n",s);
    }
}




 E-Mod


Kim刚刚学会C语言中的取模运算(mod)。他想要研究一下一个数字A模上一系列数后的结果是多少。帮他写个程序验证一下。

Input

第一行一个整数T代表数据组数。

接下来T组数据,第一行一个整数n,接下来n个数字ai

接下来一行一个整数m,接下来m个数字bi。

Output

对于每个bi,输出bi%a1%a2%...%an 。

Sample Input
1
4
10 9 5 7
5
14 8 27 11 25
Sample Output
4
3
2
1
0
Hint

在C语言中,A mod B 是 a%b

样例解释:

14%10%9%5%7=4

8%10%9%5%7=3

...

数据范围:

1<=n<=100000

1<=m<=100000

1<=ai<=1000000000

0<=bi<=1000000000

题解:求出递减子序列,再用二分法进行取余。

#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int v,m,n,a[100001];
        scanf("%d",&n);
        scanf("%d",&a[0]);
        int t=0;
        for (int i=1; i<n; i++)
        {
            scanf("%d",&v);
            if(v<a[t])
                a[++t]=v;
        }

        scanf("%d",&m);
        while(m--)
        {
            scanf("%d",&v);
            int j=0;
            while(j<=t)
            {
                int left=j,right=t,mid;
                while(right>left)
                {
                    mid=(left+right)>>1;
                    if(a[mid]>v)
                        left=mid+1;
                    else
                        right=mid;
                }
                v%=a[right];
                j=right+1;
            }
            printf("%d\n",v);
        }
    }
}

Emirp
Time Limit: 5000 MSMemory Limit: 100000 K
Total Submit: 143(59 users)Total Accepted: 61(55 users)Rating: Special Judge: No
Description

An emirp (prime spelled backwards) is a prime number that results in a different prime when its decimal digits are reversed.

The first five emirps are 13, 17, 31, 37, 71

Now Kim want to know the kth emirp. Help him.

Input

The first line is an integer T, describes the number of tests. Then T tests.

In each test, one line an integer k.

Output

For each test, output the kth emirp.

Sample Input
3
1
2
3
Sample Output
13
17
31
Hint

T<=10000

k<=1000

思路:就是找大于十的数使其本身和其反置都为素数,并且本身和其反置数不能相同。

题解:快速筛选数法。

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int vis[100001],b[1001];

void A()
{
    vis[2]=true;
    for(int i=3; i<=100001; i+=2)
        vis[i]=true;
    for(int i=3; i<=sqrt(100001); i+=2)
    {
        if(vis[i])
        {
            for(int j=i*i; j<=100001; j+=i*2)
                vis[j]=false;
        }
    }
}

int B(int m)
{
    int s=0;
    while(m)
    {
        s=s*10+m%10;
        m/=10;
    }
    return s;
}

int main()
{
    int t,n,k=1;
    A();
    for(int i=13;;i++)
    {
        if(vis[i]&&vis[B(i)]&&B(i)!=i)
        {
            b[k++]=i;
        }
        if(k>1000)
            break;
    }
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",b[n]);
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值