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

2016.4.23浙江省赛

时间:2016-04-23 19:32:46      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

A                                 Apples and Ideas


Time Limit: 2 Seconds      Memory Limit: 65536 KB

"If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas." - George Bernard Shaw

Now Alice has A apples and B ideas, while Bob has C apples and D ideas, what will they have if they exchange all things?

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The only line contains four integers ABCD (0 <= ABCD <= 100) - as the problem described.

Output

For each test case, output two lines. First line contains two integers, indicating the number of Alice‘s apples and ideas; second line contains two integers, indicating the number of Bob‘s apples and ideas.

Sample Input

4
0 0 5 30
20 25 20 0
20 25 20 15
20 25 25 30

Sample Output

5 30
0 30
20 25
20 25
20 40
20 40
25 55
20 55

题意:苹果交换数目一定,idea交换数目增倍;

AC代码:


/*签到题*/
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> using namespace std; typedef long long ll; const ll mod=1e9+7; const int N=1e5+6; int a,b,c,d; int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d%d%d",&a,&b,&c,&d); printf("%d %d\n",c,b+d); printf("%d %d\n",a,b+d); } return 0; }

 C                             Defuse the Bomb

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The bomb is about to explode! Please defuse it as soon as possible!

There is a display showing a number from 1 to 4 on the bomb. Besides this, there are 4 buttons under the display. Each button is labeled by a number from 1 to 4. The numbers on the buttons are always distinct.

技术分享

There are 5 defusing stages in total. Pressing the correct button can progress the bomb to the next defusing stage. The number on the display and the number on each button may be different in different stages. The bomb will be defused only when all 5 defusing stages get passed. Pressing the incorrect button will cause the bomb to explode immediately. Be careful!

Here is the detailed bomb defusing manual. Button positions are ordered from left to right.

Stage 1:

  • If the display is 1, press the button in the second position.
  • If the display is 2, press the button in the second position.
  • If the display is 3, press the button in the third position.
  • If the display is 4, press the button in the fourth position.

Stage 2:

  • If the display is 1, press the button labeled "4".
  • If the display is 2, press the button in the same position as you pressed in stage 1.
  • If the display is 3, press the button in the first position.
  • If the display is 4, press the button in the same position as you pressed in stage 1.

Stage 3:

  • If the display is 1, press the button with the same label you pressed in stage 2.
  • If the display is 2, press the button with the same label you pressed in stage 1.
  • If the display is 3, press the button in the third position.
  • If the display is 4, press the button labeled "4".

Stage 4:

  • If the display is 1, press the button in the same position as you pressed in stage 1.
  • If the display is 2, press the button in the first position.
  • If the display is 3, press the button in the same position as you pressed in stage 2.
  • If the display is 4, press the button in the same position as you pressed in stage 2.

Stage 5:

  • If the display is 1, press the button with the same label you pressed in stage 1.
  • If the display is 2, press the button with the same label you pressed in stage 2.
  • If the display is 3, press the button with the same label you pressed in stage 4.
  • If the display is 4, press the button with the same label you pressed in stage 3.

Input

There are multiple test cases. The first line of input is an integer T indicating the number of test cases. For each test case:

There are 5 lines. Each line contains 5 integers DB1B2B3B4 indicating the number on the display and the numbers on the buttons respectively. The i-th line correspond to the i-th stage.

Output

For each test case, output 5 lines. The i-th line contains two integers indicating the position and the label of the correct button for the i-th stage.

Sample Input

1
4 2 1 3 4
2 2 4 3 1
4 3 1 4 2
4 3 4 2 1
2 3 1 2 4

Sample Output

4 4
4 1
3 4
4 1
2 1

题意:

按给的要求找出每次操作的按钮的位置和数字;
一开始==写成=,怎么都找不出错误,最后还是老同学找的数据,然后才发现错误;

思路

感觉好几题就是这样分情况讨论;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e6+6;
int flag[8],a[10][10],pos[8],ans[8];
int main()
{

    int t;
    scanf("%d",&t);
    while(t--)
    {
        for(int i=1;i<=5;i++)
        {
            scanf("%d",&flag[i]);
            for(int j=1;j<=4;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }

        if(flag[1]==1||flag[1]==2)
        {
            pos[1]=2;
            ans[1]=a[1][2];
        }
        else
        {
            pos[1]=flag[1];
            ans[1]=a[1][pos[1]];
        }

        if(flag[2]==2||flag[2]==4)
        {
            pos[2]=pos[1];
            ans[2]=a[2][pos[2]];
        }
        else if(flag[2]==3)
        {
            pos[2]=1;
            ans[2]=a[2][1];
        }
        else
        {
            ans[2]=4;
            for(int i=1;i<=4;i++)
            {
                if(a[2][i]==4)
                {
                    pos[2]=i;
                    break;
                }
            }
        }
        if(flag[3]==1)
        {
            ans[3]=ans[2];
            for(int i=1;i<=4;i++)
            {
                if(a[3][i]==ans[3])
                {
                    pos[3]=i;
                    break;
                }
            }
        }
        else if(flag[3]==2)
        {
            ans[3]=ans[1];
            for(int i=1;i<=4;i++)
            {
                if(a[3][i]==ans[3])
                {
                    pos[3]=i;
                    break;
                }
            }
        }
        else if(flag[3]==3)
        {
            pos[3]=3;
            ans[3]=a[3][3];
        }
        else
        {
            ans[3]=4;
            for(int i=1;i<=4;i++)
            {
                if(a[3][i]==4)
                {
                    pos[3]=i;
                    break;
                }
            }
        }

        if(flag[4]==1)
        {
            pos[4]=pos[1];
            ans[4]=a[4][pos[4]];
        }
        else if(flag[4]==2)
        {
            pos[4]=1;
            ans[4]=a[4][1];
        }
        else
        {
            pos[4]=pos[2];
            ans[4]=a[4][pos[4]];
        }

        if(flag[5]==1||flag[5]==2)
        {
            ans[5]=ans[flag[5]];
            for(int i=1;i<=4;i++)
            {
                if(a[5][i]==ans[5])
                {
                    pos[5]=i;
                    break;
                }
            }
        }
        else if(flag[5]==3)
        {
            ans[5]=ans[4];
            for(int i=1;i<=4;i++)
            {
                if(a[5][i]==ans[5])
                {
                    pos[5]=i;
                    break;
                }
            }
        }
        else
        {
            ans[5]=ans[3];
            for(int i=1;i<=4;i++)
            {
                if(a[5][i]==ans[5])
                {
                    pos[5]=i;
                    break;
                }
            }
        }
        for(int i=1;i<=5;i++)
        {
            printf("%d %d\n",pos[i],ans[i]);
        }
    }

    return 0;
}

E                               Modulo Query

 

Time Limit: 2 Seconds      Memory Limit: 65536 KB

One day, Peter came across a function which looks like:

  • F(1, X) = X mod A1.
  • F(iX) = F(i - 1, X) mod Ai, 2 ≤ i ≤ N.

Where A is an integer array of length NX is a non-negative integer no greater than M.

 

Peter wants to know the number of solutions for equation F(NX) = Y, where Y is a given number.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains two integers N and M (2 ≤ N ≤ 105, 0 ≤ M ≤ 109).

The second line contains N integers: A1A2, ..., AN (1 ≤ Ai ≤ 109).

The third line contains an integer Q (1 ≤ Q ≤ 105) - the number of queries. Each of the following Q lines contains an integer Yi (0 ≤ Yi ≤ 109), which means Peter wants to know the number of solutions for equation F(NX) = Yi.

Output

For each test cases, output an integer S = (1 ⋅ Z1 + 2 ⋅ Z2 + ... + Q ⋅ ZQ) mod (109 + 7), where Zi is the answer for the i-th query.

Sample Input

1
3 5
3 2 4
5
0
1
2
3
4

Sample Output

8

题意:

给出这个式子问[0,M]有多少个满足f[N,X]=Y;0<=x<=M;

思路:
式子化简后可以知道是求[0,M]总满足 x%A1%A2%...%AN=Y的方案数;
询问较多,所以要处理出[0,M]连续取模后的结果;
可以用mp[x]存取模后小于等于x的数目,这里的是压缩存储;
每次%Ai时取出优先队列的上面>=Ai的取模,把结果更新;
再就是询问的处理,把最后队列的都取出来,(取出即有序)弄个后缀和利于得到结果,二分查找大于等于Qi的第一个位置,那么比它大的和就是结果啦,
还是看看代码吧;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e5+6;
int n,m,a[N],q,x,b[N],sum[N];
map<int,int>mp,vis;
priority_queue<int>qu;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        while(!qu.empty())qu.pop();
        mp.clear();
        vis.clear();
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        qu.push(m);
        mp[m]=1;
        vis[m]=1;
        for(int i=1;i<=n;i++)
        {
            while(!qu.empty())
            {
                int fr=qu.top();
                if(fr>=a[i])
                {
                        mp[a[i]-1]+=fr/a[i]*mp[fr];
                        mp[fr%a[i]]+=mp[fr];
                        if(!vis[a[i]-1])
                        {
                            qu.push(a[i]-1);
                            vis[a[i]-1]=1;
                        }
                        if(!vis[fr%a[i]])
                        {
                                qu.push(fr%a[i]);
                                vis[fr%a[i]]=1;
                        }

                    mp[fr]=0;
                    qu.pop();
                }
                else break;
            }
        }
        int cnt=qu.size()-1;
        int num=cnt;
        while(!qu.empty())
        {
            b[cnt--]=qu.top();
            qu.pop();
        }
        sum[num+1]=0;
        for(int i=num;i>=0;i--)
        {
            sum[i]=sum[i+1]+mp[b[i]];
        }
        scanf("%d",&q);
        ll ans=0;
        for(int i=1;i<=q;i++)
        {
            scanf("%d",&x);
            int pos=lower_bound(b,b+num+1,x)-b;
            ans+=(ll)i*(ll)sum[pos]%mod;
            ans%=mod;
        }
        cout<<ans<<"\n";
        //printf("%I64d\n",ans);
    }
    return 0;
}

 

I                               People Counting

 

Time Limit: 2 Seconds      Memory Limit: 65536 KB

In a BG (dinner gathering) for ZJU ICPC team, the coaches wanted to count the number of people present at the BG. They did that by having the waitress take a photo for them. Everyone was in the photo and no one was completely blocked. Each person in the photo has the same posture. After some preprocessing, the photo was converted into a H×W character matrix, with the background represented by ".". Thus a person in this photo is represented by the diagram in the following three lines:

.O.
/|(.)

Given the character matrix, the coaches want you to count the number of people in the photo. Note that if someone is partly blocked in the photo, only part of the above diagram will be presented in the character matrix.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first contains two integers HW (1 ≤ HW ≤ 100) - as described above, followed by H lines, showing the matrix representation of the photo.

Output

For each test case, there should be a single line, containing an integer indicating the number of people from the photo.

Sample Input

2
3 3
.O.
/|(.)
3 4
OOO(
/|\()))

Sample Output

1
4

题意:

给一个人的形态,再给一张照片,问这里面有多少人;

思路:

人的形态是固定的,那么根据一个部位搜索剩下的部位就好了;


AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e5+6;
char s[110][110];
int n,m,flag[7],vis[110][110],ans=0;
int check(int x,int y)
{
    if(s[x][y]==O)
    {
        int fx=x+1,fy=y;
        if(fx<n&&s[fx][fy]==|)
        {
            vis[fx][fy]=1;
        }
        fx=x+2,fy=y-1;
        //cout<<fx<<" "<<fy<<"%"<<" "<<s[fx][fy]<<endl;
        if(fx<n&&fy>=0&&s[fx][fy]==()
        {
            vis[fx][fy]=1;
        }
        fx=x+2,fy=y+1;
        if(fx<n&&fy<m&&s[fx][fy]==))
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y-1;
        if(fx<n&&fy>=0&&s[fx][fy]==/)
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y+1;
        if(fx<n&&fy<m&&s[fx][fy]==92)
        {
            vis[fx][fy]=1;
        }
        ans++;
    }
    else if(s[x][y]==/)
    {

        int fx=x,fy=y+1;
        if(fy<m&&s[fx][fy]==|)
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y;
        if(fx<n&&fy>=0&&s[fx][fy]==()
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y+2;
        if(fx<n&&fy<m&&s[fx][fy]==))
        {
            vis[fx][fy]=1;
        }
        fx=x-1,fy=y+1;
        if(fx>=0&&fy<m&&s[fx][fy]==O)
        {
            vis[fx][fy]=1;
        }
        fx=x,fy=y+2;
        if(fx<n&&fy<m&&s[fx][fy]==92)
        {
            vis[fx][fy]=1;
        }
        ans++;
    }
   else if(s[x][y]==|)
    {
        int fx=x-1,fy=y;
        if(fx>=0&&s[fx][fy]==O)
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y-1;
        if(fx<n&&fy>=0&&s[fx][fy]==()
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y+1;
        if(fx<n&&fy<m&&s[fx][fy]==))
        {
            vis[fx][fy]=1;
        }
        fx=x,fy=y-1;
        if(fx<n&&fy>=0&&s[fx][fy]==/)
        {
            vis[fx][fy]=1;
        }
        fx=x,fy=y+1;
        if(fx<n&&fy<m&&s[fx][fy]==92)
        {
            vis[fx][fy]=1;
        }
        ans++;
    }
    else if(s[x][y]==92)
    {
        int fx=x,fy=y-1;
        if(fy>=0&&s[fx][fy]==|)
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y-2;
        if(fx<n&&fy>=0&&s[fx][fy]==()
        {
            vis[fx][fy]=1;
        }
        fx=x+1,fy=y;
        if(fx<n&&fy<m&&s[fx][fy]==))
        {
            vis[fx][fy]=1;
        }
        fx=x,fy=y-2;
        if(fx<n&&fy>=0&&s[fx][fy]==/)
        {
            vis[fx][fy]=1;
        }
        fx=x-1,fy=y-1;
        if(fx>=0&&fy>=0&&s[fx][fy]==O)
        {
            vis[fx][fy]=1;
        }
        ans++;
    }
    else if(s[x][y]==()
    {
        int fx=x-1,fy=y+1;
        if(fx>=0&&fy<m&&s[fx][fy]==|)
        {
            vis[fx][fy]=1;
        }
        fx=x-2,fy=y+1;
        if(fx>=0&&fy<m&&s[fx][fy]==O)
        {
            vis[fx][fy]=1;
        }
        fx=x,fy=y+2;
        if(fx<n&&fy<m&&s[fx][fy]==))
        {
            vis[fx][fy]=1;
        }
        fx=x-1,fy=y;
        if(fx>=0&&fy>=0&&s[fx][fy]==/)
        {
            vis[fx][fy]=1;
        }
        fx=x-1,fy=y+2;
        if(fx>=0&&fy<m&&s[fx][fy]==92)
        {
            vis[fx][fy]=1;
        }
        ans++;
    }
    else if(s[x][y]==))
    {
        int fx=x-1,fy=y-1;
        if(fx>=0&&fy>=0&&s[fx][fy]==|)
        {
            vis[fx][fy]=1;
        }
        fx=x,fy=y-2;
        if(fx<n&&fy>=0&&s[fx][fy]==()
        {
            vis[fx][fy]=1;
        }
        fx=x-2,fy=y-1;
        if(fx>=0&&fy>=0&&s[fx][fy]==O)
        {
            vis[fx][fy]=1;
        }
        fx=x-1,fy=y-2;
        if(fx>=0&&fy>=0&&s[fx][fy]==/)
        {
            vis[fx][fy]=1;
        }
        fx=x-1,fy=y;
        if(fx>=0&&fy<m&&s[fx][fy]==92)
        {
            vis[fx][fy]=1;
        }
        ans++;
    }
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ans=0;
        memset(flag,0,sizeof(flag));
        memset(vis,0,sizeof(vis));
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(!vis[i][j])
                {
                   // cout<<i<<" "<<j<<"@"<<endl;
                check(i,j);
                }
            }
        }
        printf("%d\n",ans);
    }

    return 0;
}

K                                      Highway Project

 

Time Limit: 2 Seconds      Memory Limit: 65536 KB

Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project.

The Marjar Empire has N cities (including the capital), indexed from 0 to N - 1 (the capital is 0) and there are M highways can be built. Building the i-th highway costs Cidollars. It takes Di minutes to travel between city Xi and Yi on the i-th highway.

Edward wants to find a construction plan with minimal total time needed to reach other cities from the capital, i.e. the sum of minimal time needed to travel from the capital to city i (1 ≤ i ≤ N). Among all feasible plans, Edward wants to select the plan with minimal cost. Please help him to finish this task.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first contains two integers NM (1 ≤ NM ≤ 105).

Then followed by M lines, each line contains four integers XiYiDiCi (0 ≤ XiYi < N, 0 < DiCi < 105).

Output

For each test case, output two integers indicating the minimal total time and the minimal cost for the highway project when the total time is minimized.

Sample Input

2
4 5
0 3 1 1
0 1 1 1
0 2 10 10
2 1 1 1
2 3 1 2
4 5
0 3 1 1
0 1 1 1
0 2 10 10
2 1 2 1
2 3 1 2

Sample Output

4 3
4 4

题意

给一个图,应该是一个连通图,问找到点0到所有点的最小距离和,并且在保证距离最小的同时修这些路的花费最少;


思路

一个Dijkstra的题;在找最小距离的选边的时候考虑花费就好了,还不知道这样对不对,代码是比赛完了才搞好的,还没交过;

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e5+6;
int n,m,dis[N],head[N],cnt,vis[N],u,v,ti,co;
struct Edge
{
    friend bool operator< (Edge x,Edge y)
    {
        if(x.time==y.time)return x.cost>y.cost;
        return x.time>y.time;
    }
    int from,to,next,cost,time;
};
Edge edge[3*N];
void add_edge(int s,int e,int a,int b)
{
    edge[cnt].from=s;
    edge[cnt].to=e;
    edge[cnt].next=head[s];
    edge[cnt].time=a;
    edge[cnt].cost=b;
    head[s]=cnt++;
}
priority_queue<Edge>qu;
int bfs()
{
    memset(vis,0,sizeof(vis));
    ll ansti=0,ansco=0;
    vis[1]=1;
    for(int i=head[1];i!=-1;i=edge[i].next)
    {
        qu.push(edge[i]);
    }
    dis[1]=0;
    while(!qu.empty())
    {
        Edge fr=qu.top();
        qu.pop();
        if(!vis[fr.to])
        {
            vis[fr.to]=1;
            dis[fr.to]=dis[fr.from]+fr.time;
            ansti+=(ll)dis[fr.to];
            ansco+=(ll)fr.cost;
            for(int i=head[fr.to];i!=-1;i=edge[i].next)
            {
              if(!vis[edge[i].to])
              {
                  qu.push(edge[i]);
              }
            }
        }
    }
    cout<<ansti<<" "<<ansco<<"\n";
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        cnt=0;
        memset(head,-1,sizeof(head));
        scanf("%d%d",&n,&m);
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d%d",&u,&v,&ti,&co);
            add_edge(u+1,v+1,ti,co);
            add_edge(v+1,u+1,ti,co);
        }
        bfs();
    }
    return 0;
}

L                             Very Happy Great BG

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The summer training of ZJU ICPC in July is about to end. To celebrate this great and happy day, the coach of ZJU ICPC Team decided to BG everyone!

技术分享

After a brief discussion, they decided to go to Lou Wai Lou to have a great dinner. Each team member can bring some friends with him/her. Of course, they need to tell the coach the number of friends they will bring.

Now the coach wants to know the total number of participants (excluding the coach himself). Please tell him.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first line contains an integer N (1 <= N <= 40) - the number of ZJU ICPC members.

The second line contains N non-negative integers, the i-th integer indicates the number of friends (< 1000) that the i-th team member will bring.

Output

For each test case, output the total number of participants.

Sample Input

4
5
0 0 1 2 3
1
0
10
1 2 3 4 5 6 7 8 9 10
2
5 3

Sample Output

11
1
65
10

题意

问一共有多少人,包括本人及本人带的人;

AC代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=1e5+6;
int a,b,c,d,n;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a);
            ans+=a+1;
        }
        printf("%d\n",ans);
    }

    return 0;
}

 



2016.4.23浙江省赛

标签:

原文地址:http://www.cnblogs.com/zhangchengc919/p/5425128.html

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