2018浙江校赛

A:Pretty Matrix     ZOJ  4014
题目大意:给一个n*m型矩阵,然后给一个A和B,问矩阵中有元素不符合  a[i,j]>=A  &&   a[i,j]<=B ,所以直接统计满足 
a[i][j]<A || a[i][j]>B 有多少元素即可。
这里有一个隐含条件:当 A>B 时,矩阵中的每一个元素都是不符合条件的,输出  No Solution
代码:
 

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL  long long
using namespace std;
int a[110][110];
int main(){
     int n,m,A,B;
     int T;
     while(scanf("%d",&T)!=EOF){
         while(T--){
         scanf("%d%d%d%d",&n,&m,&A,&B);
         int num=0;
         //if(A>B){int t=A;A=B;B=t;}
         for(int i=0;i<n;i++)
         for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
            if(a[i][j]<A||a[i][j]>B) num++;
        }
        if(A>B) cout<<"No Solution"<<endl;
        else
            cout<<num<<endl;
        }
    }

    return 0;
}

E: Crosses Puzzles     ZOJ  4018
题目大意:

G:Traffic Light    ZOJ 4020
题目大意:T个测试案例,每个案例包含一个n*m型矩阵,接下来是起始位置与终止位置。问从起始位置到终止位置最少要走几步。走不到便输出-1。其中,n*m型矩阵中的 0 元素代表只能向上或向下走; 1  元素只能代表向左或向右走。而且这里还会按规则的进行改变,第一步按照给定的元素的规则走,第二步,进行 0变1   1变0 的反转,第三步,继续按给的值执行,第四部反转。
注意:反转方式
代码:
 

#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
using namespace std;
const int maxn=100010;
int m,n;
int fx,fy,ex,ey;
int dir0[2][2]={0,1,0,-1};
int dir1[2][2]={1,0,-1,0};
struct node{
   int x,y,step;
};
vector<int>mp[maxn];
int bfs(node st){
     int vis[n][m];
     memset(vis,0,sizeof(vis));
     queue<node>Q;
     Q.push(st);
     int ans = 0;//统计走的步数
     while(!Q.empty()){
        node u = Q.front();
        Q.pop();
        if(u.x == (ex-1) && u.y == (ey-1)){
            ans = u.step;
            return ans;
        }
        if(u.step%2==0){//执行本身操作
            if(mp[u.x][u.y]){//本身为1
                for(int i=0;i<2;i++){
                    node t = u;
                    t.x += dir0[i][0];
                    t.y += dir0[i][1];
                    if(!vis[t.x][t.y] && t.x<n && t.x>=0 && t.y<m && t.y>=0){
                        t.step++;
                        vis[t.x][t.y]=1;
                        Q.push(t);
                    }

                }
            }
            else{//本身为0
                for(int i=0;i<2;i++){
                    node t = u;
                    t.x += dir1[i][0];
                    t.y += dir1[i][1];
                    if(!vis[t.x][t.y] && t.x<n && t.x>=0 && t.y<m && t.y>=0){
                        t.step++;
                        vis[t.x][t.y]=1;
                        Q.push(t);
                    }

                }
            }
        }
        else{//反转
              if(!mp[u.x][u.y]){//本身为1时,反转为0
                for(int i=0;i<2;i++){
                    node t = u;
                    t.x += dir0[i][0];
                    t.y += dir0[i][1];
                    if(!vis[t.x][t.y] && t.x<n && t.x>=0 && t.y<m && t.y>=0){
                        t.step++;
                        vis[t.x][t.y]=1;
                        Q.push(t);
                    }

                }
            }
            else{
                for(int i=0;i<2;i++){
                    node t = u;
                    t.x += dir1[i][0];
                    t.y += dir1[i][1];
                    if(!vis[t.x][t.y] && t.x<n && t.x>=0 && t.y<m && t.y>=0){
                        t.step++;
                        vis[t.x][t.y]=1;
                        Q.push(t);
                    }

                }
            }
        }
     }
     return -1;
}
int main(){
    int T;
    while(scanf("%d",&T)!=EOF){
        while(T--){
            scanf("%d%d",&n,&m);
            for(int i=0;i<maxn;i++)
            mp[i].clear();
            for(int i=0;i<n;i++)
             for(int j=0;j<m;j++){
                int x;
                cin>>x;
                mp[i].push_back(x);
             }
             scanf("%d%d%d%d",&fx,&fy,&ex,&ey);
             node st;
             st.x = fx-1;
             st.y = fy-1;
             st.step = 0;

             int ans = bfs(st);
             if(ans<0) cout<<-1<<endl;
             else cout<<ans<<endl;
        }
    }
    return 0;
}

J:PPAP    ZOJ 4023
题目大意:给两个字符串,将第一个字符串连到第二个字符串之后,且将第二个字符串的首字母变大写。
代码:
 

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define LL  long long
using namespace std;
int main(){
     char a[32],b[32];
     int T;
     while(scanf("%d",&T)!=EOF){
        cin>>a;cin>>b;
        b[0]=b[0]-32;
        cout<<b<<a<<endl;
     }

    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值