Testing Round #16 (Unrated)

B. Square?

 
题目链接:https://codeforces.ml/contest/1351/problem/B

    #include <bits/stdc++.h>
    #define rush() int T;cin>>T;while(T--)
    #define go(a) while(cin>>a)
    #define ms(a,b) memset(a,b,sizeof a)
    #define E 1e-8
    using namespace std;
    typedef __int64 ll;
    const int idata=5e4+5;
     
    ll n,m,t,_;
    int i,j,k;
    int cnt,num,ans;
    int minn,maxx;
    stack<int>stk;
    priority_queue<ll,vector<ll>,less<ll> >q;
    map<ll,int>mp;
    ll a[idata];
     
    int main()
    {
        cin.tie(0);
        iostream::sync_with_stdio(false);
        rush()
        {
            int a,b,c,d;
            bool judge=0;
            cin>>a>>b>>c>>d;
            if(a>b) swap(a,b);
            if(c<d) swap(c,d);
            if(b==c&&a+d==c){
                    judge=1;
            }
            if(judge) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        return 0;
    }

C. Skier

 
题目链接:https://codeforces.ml/contest/1351/problem/C

 关于这个题,显然用数组是不科学的,内存太大,所以用map,当时也考虑了用pair,但是官方的提示

A path segment means an edge of length 1 meter between points.

并不知道 要怎么实现,所以最后只通过了样例

//我的代码
#include <bits/stdc++.h>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
using namespace std;
typedef __int64 ll;
const int idata=1e6+5;

ll n,m,t,_;
int i,j,k;
int cnt,num,ans;
int minn,maxx;
stack<int>stk;
priority_queue<ll,vector<ll>,less<ll> >q;
map<pair<int,int>,int>mp;
string s;

int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(false);
    rush()
    {
        cin>>s;
        mp.clear();
        //cout<<mp[make_pair(1,1)]<<"455"<<endl;
        int x=0,y=0;
        ll sum=0;
        mp[make_pair(x,y)]=1;
        for(i=0;i<s.size();i++){
            if(s[i]=='N') y++;
            else if(s[i]=='S') y--;
            else if(s[i]=='W') x--;
            else if(s[i]=='E') x++;
            if(mp[make_pair(x,y)]){
                sum+=1;
            }
            else{
                sum+=5;
                mp[make_pair(x,y)]=1;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}

以下是 某位大佬的通过代码:

#include <bits/stdc++.h>
#define rush() int T;cin>>T;while(T--)
#define go(a) while(cin>>a)
#define ms(a,b) memset(a,b,sizeof a)
#define E 1e-8
using namespace std;
typedef __int64 ll;
const int idata=1e6+5;

ll n,m,t,_;
int i,j,k;
int cnt,num,ans;
int minn,maxx;
map<pair<int,int>,int>mp,judge;
string s;

int main()
{
    cin.tie(0);
    iostream::sync_with_stdio(false);
    rush()
    {
        cin>>s;
        mp.clear();
        judge.clear();
        int x=0,y=0;
        ll sum=0;
        mp[make_pair(x,y)]=1;
        int cnt=1,pre,now;
        for(i=0;i<s.size();i++){
            pre=mp[make_pair(x,y)];
            if(s[i]=='N') y++;
            else if(s[i]=='S') y--;
            else if(s[i]=='W') x--;
            else if(s[i]=='E') x++;
            if(mp[make_pair(x,y)]==0){
                //记录一共走到了第几个点
                mp[make_pair(x,y)]=++cnt;
            }
            now=mp[make_pair(x,y)];
            if(judge[make_pair(pre,now)]==0&&judge[make_pair(now,pre)]==0) sum+=5;
            else sum+=1;

            judge[make_pair(pre,now)]=judge[make_pair(now,pre)]=1;
        }
        cout<<sum<<endl;
    }
    return 0;
}

原创文章 410 获赞 16 访问量 3万+

猜你喜欢

转载自blog.csdn.net/C_Dreamy/article/details/106004028