0
已解决
为什么超时啊!
60分代码:
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
using namespace std;
int main(){
string n;
cin>>n;
long long int;
cin>>t;
long long int x=0,y=0;
for(int i=0;i<=t-1;i++){
if(i==n.size()){
n+=n;
}
if(n[i]=='E'){
x++;
}
if(n[i]=='S'){
y--;
}
if(n[i]=='W'){
x--;
}
if(n[i]=='N'){
y++;
}
}
cout<<x<<" "<<y;
return 0;
}
有什么办法不超时吗?
0
0
0
0
用到了周期问题,并兼模拟,如果只用for循环或while循环,e,不说了,自己看 <数据范围及提示 Data Size & Hint>:对于100%的数据:T<=2000000000 肯定会超时鸭
0
0