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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章