天天看點

The 13th Zhejiang Provincial Collegiate Programming Contest

Apples and Ideas

Time Limit: 2 Seconds      Memory Limit: 65536 KB

A 簡單題

"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 A, B, C, D (0 <= A, B, C, D <= 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








       
#include <bits/stdc++.h>
 #define LL long long
 using namespace std;
 int main()
 {
    int A,B,C,D;
    int t;
    cin>>t;
    while(t--)
    {
        cin>>A>>B>>C>>D;
        cout<<C<<" "<<D+B<<endl;cout<<A<<" "<<B+D<<endl;

    }
     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.
The 13th Zhejiang Provincial Collegiate Programming Contest
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 D, B1, B2, B3, B4 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
      

Hint

Keep talking with your teammates and nobody explodes! 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#define LL long long
#include<string>
#include<cmath>
#define INF 0x3f3f3f3f
using namespace std;
int arr[10][10];
int ans[10];
int main(){
	int n,m,i,j,k,cla;
	scanf("%d",&cla);
	while(cla--){

		for(i = 1;i <= 5;++ i){
			scanf("%d",&k);
			for(j = 1;j <= 4;++ j){
				scanf("%d",&arr[i][j]);
			}
			if(i == 1){

				if(k==1){
					printf("2 %d\n",arr[1][2]);
					ans[1] = 2;
				}
				else if( k== 2){
					printf("2 %d\n",arr[1][2]);
					ans[1] = 2;
				}
				else if(k == 3){
					printf("3 %d\n",arr[1][3]);
					ans[1] = 3;
				}
				else if(k == 4 ){
					printf("4 %d\n",arr[1][4]);
					ans[1] = 4;
				}
			}
			else if(i == 2){
				if(k==1){
					int bj;
					for(j = 1;j <=4 ;++ j)
						if(arr[2][j]==4)
							bj = j;
					printf("%d 4\n",bj);
					ans[2] = bj;
				}
				else if( k== 2){
					printf("%d %d\n",ans[1],arr[2][ans[1]]);
					ans[2] = ans[1];
				}
				else if(k== 3 ){
					printf("1 %d\n",arr[2][1]);
					ans[2] = 1;
				}
				else if(k== 4 ){
					printf("%d %d\n",ans[1],arr[2][ans[1] ]);
					ans[2] = ans[1];
				}
			}
			else if(i == 3){
				if(k==1){
					int tmp,bj = arr[2][ans[2]];
					for(j = 1;j <= 4;++ j)
						if(bj == arr[3][j] )
						   tmp=j;
					printf("%d %d\n",tmp,arr[3][tmp]);
					ans[3] = tmp;
				}

				else if( k== 2){
					int tmp,bj = arr[1][ ans[1] ];
					for(j =1;j <= 4;++ j){
						if(bj==arr[3][j]){
							tmp = j;
						}
					}
					printf("%d %d\n",tmp,arr[3][tmp]);
					ans[3] = tmp;
				}

				else if(k== 3 ){
					printf("3 %d\n",arr[3][3]);
					ans[3] = 3;
				}
				else if(k == 4 ){
					int bj ;
					for(j =1;j <= 4;++ j){
						if(4==arr[3][j]){
							bj = j;
						}
					}
					printf("%d 4\n",bj);
					ans[3] = bj;
				}
			}

			else if(i == 4){
				if(k == 1){
					printf("%d %d\n",ans[1],arr[4][ans[1]]);
					ans[4] = ans[1];
				}
				else if(k == 2){
					printf("1 %d\n",arr[4][1]);
					ans[4] = 1;
				}
				else if(k== 3){
					printf("%d %d\n",ans[2],arr[4][ans[2]]);
					ans[4] = ans[2];
				}
				else if(k == 4){
					printf("%d %d\n",ans[2],arr[4][ans[2]]);
					ans[4] = ans[2];
				}
			}
			else if(i== 5){
				if(k == 1){
					int tmp,bj=ans[1];
					for(j = 1;j <= 4;++ j){
						if(arr[1][ans[1] ] ==arr[5][j] )
							tmp = j;
					}
					printf("%d %d\n",tmp,arr[5][tmp]);
				}

				else if(k == 2){
					int tmp,bj=ans[2];
					for(j = 1;j <= 4;++ j){
						if(arr[2][ans[2] ] ==arr[5][j] )
							tmp = j;
					}
					printf("%d %d\n",tmp,arr[5][tmp]);
				}
				else if(k == 3){
					int tmp,bj=ans[4];
					for(j = 1;j <= 4;++ j){
						if(arr[4][ans[4] ] ==arr[5][j] )
							tmp = j;
					}
					printf("%d %d\n",tmp,arr[5][tmp]);
				}
				else if(k == 4){
					int tmp,bj=ans[3];
					for(j = 1;j <= 4;++ j){
						if(arr[3][ans[3] ] ==arr[5][j] )
							tmp = j;
					}
					printf("%d %d\n",tmp,arr[5][tmp]);
				}
			}
		}
	}
	return 0;
}
           

D模拟,閏年的規律是400年一個周期,恰好是七的倍數。

The Lucky Week Time Limit: 2 Seconds      Memory Limit: 65536 KB

Edward, the headmaster of the Marjar University, is very busy every day and always forgets the date.

There was one day Edward suddenly found that if Monday was the 1st, 11th or 21st day of that month, he could remember the date clearly in that week. Therefore, he called such week "The Lucky Week".

But now Edward only remembers the date of his first Lucky Week because of the age-related memory loss, and he wants to know the date of the N-th Lucky Week. Can you help him?

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:

The only line contains four integers Y, M, D and N (1 ≤ N ≤ 109) indicating the date (Y: year, M: month, D: day) of the Monday of the first Lucky Week and the Edward's query N.

The Monday of the first Lucky Week is between 1st Jan, 1753 and 31st Dec, 9999 (inclusive).

Output

For each case, print the date of the Monday of the N-th Lucky Week.

Sample Input

2
2016 4 11 2
2016 1 11 10
      

Sample Output

2016 7 11
2017 9 11
      
#include <bits/stdc++.h>

using namespace std;

struct node
{
    int y,m,d;

}p[6010];
int num=0;
void init()
{
  //  int sumday=0;
    int week=0;
    int tmp=1753+800;
    for(int year=1753;year<tmp;year++)
    {
        if(year%4==0&&year%100!=0||year%400==0)
        {
            for(int mon=1;mon<=12;mon++)
            {

                if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)
                {
                    for(int day=1;day<=31;day++)
                    {
                       // sumday+=1;
                        week%=7;
                        if(week%7==0&&(day==1||day==11||day==21))
                        {
                            p[num].y=year;
                            p[num].m=mon;
                            p[num++].d=day;
                        }
                            week++;
                    }
                }
                else if(mon==2)
                {
                    for(int day=1;day<=29;day++)
                    {
                        //sumday+=1;
                        week%=7;
                        if(week%7==0&&(day==1||day==11||day==21))
                        {
                            p[num].y=year;
                            p[num].m=mon;
                            p[num++].d=day;
                        }
                            week++;
                    }
                }
                else if(mon==4||mon==6||mon==9||mon==11)
                {
                    for(int day=1;day<=30;day++)
                    {
                        //sumday+=1;
                        week%=7;
                        if(week%7==0&&(day==1||day==11||day==21))
                        {
                            p[num].y=year;
                            p[num].m=mon;
                            p[num++].d=day;
                        }
                            week++;
                    }
                }
            }
        }
        else
        {
            for(int mon=1;mon<=12;mon++)
            {
                if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)
                {
                    for(int day=1;day<=31;day++)
                    {
                        //sumday+=1;
                        week%=7;
                        if(week%7==0&&(day==1||day==11||day==21))
                        {
                            p[num].y=year;
                            p[num].m=mon;
                            //p[num].num=sumday;
                            p[num++].d=day;
                        }
                            week++;
                    }
                }
                else if(mon==2)
                {
                    for(int day=1;day<=28;day++)
                    {
                        //sumday+=1;
                        week%=7;
                        if(week%7==0&&(day==1||day==11||day==21))
                        {

                            p[num].y=year;
                            p[num].m=mon;
                            p[num++].d=day;
                        }
                            week++;
                    }
                }
                else if(mon==4||mon==6||mon==9||mon==11)
                {
                    for(int day=1;day<=30;day++)
                    {
                      //  sumday+=1;
                        week%=7;
                        if(week%7==0&&(day==1||day==11||day==21))
                        {
                            p[num].y=year;
                            p[num].m=mon;
                            p[num++].d=day;
                        }
                            week++;
                    }
                }
            }
        }
        if(num>=4116)break;
    }

}
int main()
{
    int t;

   //freopen("stdin.txt","w+",stdout);
     init();
    int i;

        cin>>t;
        while(t--)
        {
            int years,mons,days,ge;
            scanf("%d%d%d%d",&years,&mons,&days,&ge);
             years+=(ge-1)/2058*400;
             int mod=(ge-1)%2058;
             for(i=0;i<2058;i++)
             {
                 if((years-p[i].y)%400==0&&p[i].m==mons&&p[i].d==days)
                 {
                    break;
                 }
             }
             printf("%d %d %d\n",years+(p[i+mod].y-p[i].y),p[mod+i].m,p[mod+i].d);
        }
    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 H, W (1 ≤ H, W ≤ 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
      
#include <bits/stdc++.h>
 #define LL long long
 using namespace std;
 char s[110][110];
 int A[128];
 int vis[110][110];
 int ans;
  int t,n,m;
 int ch[][6][2]={{1,-1,1,0,1,1,2,-1,2,1},{0,0,1,-1,1,0,1,1,2,-1,2,1},
 {-1,-1,0,0,0,1,0,2,1,0,1,2},{-1,0,0,-1,0,0,0,1,1,-1,1,1},
 {-1,-1,0,-2,0,-1,0,0,1,-2,1,0},{-2,1,-1,0,-1,1,-1,2,0,0,0,2},
 {-2,-1,-1,-2,-1,-1,-1,0,0,-2,0,0}};
 char ss[]="O/|\\()";
bool ok(int x,int y)
{
    if(x>=0&&x<n&&y>=0&&y<m&&s[x][y]!='.')
return 1;
return 0;
}


 void DFS(char c,int x,int y)
 {
    int tmp=A[c];
    int xx,yy;
    for(int i=0;i<6;i++)
    {
        xx=x+ch[tmp][i][0];
        yy=y+ch[tmp][i][1];
        if(ok(xx,yy))
        {
            if(s[xx][yy]==ss[i])
                vis[xx][yy]=1;
        }
    }
 }

 int main()
 {
     memset(A,0,sizeof(A));
     A['O']=1;
     A['/']=2;
     A['|']=3;
     A['\\']=4;
     A['(']=5;
     A[')']=6;
    cin>>t;

    while(t--)
    {
        cin>>n>>m;
        for(int i=0;i<n;i++)
        {
            scanf("%s",s[i]);
        }
        int ans=0;
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(A[s[i][j]]&&!vis[i][j])
                {
                    ans++;
                    DFS(s[i][j],i,j);
                }
            }
        }
        printf("%d\n",ans);
    }
     return 0;
 }
           

大神的寫法,遇到身體部位,都标記成腿;

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

char str[110][110];
bool has[110][110];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int T;
	int n,m;
	scanf("%d",&T);
	while(T--) {
		scanf("%d%d",&n,&m);
		for(int i = 0;i < n;i++)
			scanf("%s", str[i]);
		memset(has,false,sizeof(has));
		for(int i = 0;i < n;i++)
			for(int j = 0;j < m;j++) {
				if(str[i][j] == 'O')has[i+2][j+1] = true;
				if(str[i][j] == '/')has[i+1][j+2] = true;
				if(str[i][j] == '|')has[i+1][j+1] = true;
				if(str[i][j] == '\\')has[i+1][j] = true;
				if(str[i][j] == '(')has[i][j+2] = true;
				if(str[i][j] == ')')has[i][j] = true;
			}
		int ans = 0;
		for(int i = 0;i < n+3;i++)
			for(int j = 0;j < m+3;j++)
				if(has[i][j])
					ans++;
		printf("%d\n",ans);
	}
    return 0;
}
           

K 最短路(SPFA)

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 Ci dollars. 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 N, M (1 ≤ N, M ≤ 105).

Then followed by M lines, each line contains four integers Xi, Yi, Di, Ci (0 ≤ Xi, Yi < N, 0 < Di, Ci < 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
      
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e5+1110;
const LL INF = 1e12;
struct  node
{
    LL v,w,p;
    int next;
} T[N<<1];

LL dis[N];
LL value[N];
int head[N];
int top;
int n,m;
int vis[N];

void build(int u,int v,LL w,LL p)
{
    T[top].p=p;
    T[top].v=v;
    T[top].w=w;
    T[top].next=head[u];
    head[u]=top++;
}
void SPFA()
{
    memset(vis,0,sizeof(vis));
    vis[0]=1;
    queue<int>Q;
    Q.push(0);
    for(int i=0; i<n; i++)
        dis[i]=INF,value[i]=INF;
    dis[0]=value[0]=0;
    int tmp,v;
    LL now1,nowp,w,p;
    while(!Q.empty())
    {
        tmp=Q.front(),Q.pop();
        vis[tmp]=0;
        for(int i=head[tmp]; i!=-1; i=T[i].next)
        {
            v=T[i].v,w=T[i].w,p=T[i].p;
            now1=dis[tmp]+w;
            if(now1<dis[v]||(now1==dis[v]&&p<value[v]))
            {
                dis[v]=now1,value[v]=p;
                if(!vis[v])
                {
                    vis[v]=1;
                    Q.push(v);
                }
            }
        }
    }
    LL ans1=0,ans2=0;
    for(int i=1; i<n; i++)
    {
        ans1+=dis[i];ans2+=value[i];
    }
    cout<<ans1<<" "<<ans2<<endl;
}
int main()
{

    int t;
    cin>>t;
    int u,v;
    LL w,p;
    while(t--)
    {
        memset(head,-1,sizeof(head));
        top=0;
        scanf("%d%d",&n,&m);
        for(int i=0; i<m; i++)
        {
            scanf("%d%d%lld%lld",&u,&v,&w,&p);
            build(v,u,w,p);
            build(u,v,w,p);
        }
        SPFA();
    }
    return 0;
}
           
L 水題啦~
           
<center><span class="bigProblemTitle">Very Happy Great BG</span></center><hr /><center><span style="color:green;">Time Limit: </span>2 Seconds      <span style="color:green;">Memory Limit: </span>65536 KB </center><hr /><p>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! </p><center><img src="http://acm.zju.edu.cn/onlinejudge/showImage.do?name=LouWaiLou.jpg" alt="" /></center><p>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. </p><p>Now the coach wants to know the total number of participants (excluding the coach himself). Please tell him. </p><h4>Input</h4><p>There are multiple test cases. The first line of input contains an integer <var>T</var> indicating the number of test cases. For each test case:</p><p>The first line contains an integer <var>N</var> (1 <= <var>N</var> <= 40) - the number of ZJU ICPC members. </p><p>The second line contains <var>N</var> non-negative integers, the <var>i</var>-th integer indicates the number of friends (< 1000) that the <var>i</var>-th team member will bring. </p><h4>Output</h4><p>For each test case, output the total number of participants. </p><h4>Sample Input</h4><pre>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
      
#include <bits/stdc++.h>
 #define LL long long
 using namespace std;
 int a[100];
 int main()
 {
    int T,n;
    while(~scanf("%d",&T))
    {
        while(T--)
        {
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
                scanf("%d",&a[i]);
            LL sum=n;
            for(int i=1;i<=n;i++)
            {
                sum=sum+a[i];
            }
            printf("%lld\n",sum);
        }
    }
     return 0;
 }