根据难度排序。
个人总结向。
如果有什么讲的不清楚的欢迎留言私信交流~
L. Problem L is the Only Lovely Problem(签到)
题意: 判断字符串是否有 lovely 开头。
思路: 模拟
代码:
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define eps 1e-10
using namespace std;
const int manx=1e6+5;
const int N=5e3+5;
//const int mod=1e9+7;
const int mod=998244353;
const ull mo=233;
int main(){
string s; cin>>s;
for(int i=0;i<s.size();i++) s[i]=tolower(s[i]);
if(s.size()>=6){
if(s.substr(0,6)=="lovely") cout<<"lovely"<<endl;
else cout<<"ugly"<<endl;
}else cout<<"ugly"<<endl;
return 0;
} B. Classical String Problem(思维)
题意: 时,输出当前字符串第x个字符,
时,如果 x>0,把字符串最左边的x个字符放到字符串右边,
把字符串最右边
个字符放到字符串左边。
思路:
8e5 的询问破灭暴力的想法。
考虑字符串无论怎么变化,始终是一个环。
参考双向队列求长度的取模操作即可。
代码:
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define eps 1e-10
#define io std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int manx=2e6+5;
const int N=5e3+5;
//const int mod=1e9+7;
const int mod=998244353;
const ull mo=233;
char s[manx];
char c[5];
int main(){
scanf("%s",s); ll n=strlen(s);
ll p; scanf("%lld",&p); ll q=0;
while(p--){
ll x; scanf("%s%lld",c,&x);
if(c[0]=='A') printf("%c\n",s[(x+q-1)%n]);
else {
q+=x;
q=(q+n)%n;
}
}
return 0;
} C. Operation Love(计算几何)
题意: 给出20个二维平面的点,可能是浮点数,但是顺序或者倒序连接之后一定是图中左手或者右手的图案,判断给出的图像是左手还是右手?
思路:
队友一发过太顶了。
判断最长两条边的位置。
代码:
#include <bits/stdc++.h>
#define inf 1000000009
#define db printf("where!\n");
#define pb push_back
using namespace std;
#define ll long long
#define MP std::make_pair
ll gcd(ll x,ll y){return y ? gcd(y,x%y) : x;}
template<class T>inline void read(T &res){
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
struct P
{
double x,y;
};
P a[25];
double le(P a,P b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool cmp(P a,P b)
{
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int main()
{
int t;read(t);
while(t--){
for(int i=1;i<=20;i++){
cin>>a[i].x>>a[i].y;
}
P b[2];
int temp=0;
for(int i=1;i<=20&&!temp;i++){
for(int j=i+1;j<=20;j++){
if(abs(le(a[i],a[j])-9)<=0.00001){
b[1].x=a[i].x,b[0].x=a[j].x;
b[1].y=a[i].y,b[0].y=a[j].y;
temp=1;
break;
}
}
}
sort(b,b+2,cmp);
//cout<<b[0].x<<" "<<b[0].y<<endl;
//cout<<b[1].x<<" "<<b[1].y<<endl;
temp=3;
P c;
for(int i=1;i<=20&&temp==3;i++){
if(abs(le(b[0],a[i])-sqrt(145))<=0.0001){
temp=1;
c.x=a[i].x,c.y=a[i].y;
}
}
for(int i=1;i<=20&&temp==3;i++){
if(abs(le(b[1],a[i])-sqrt(145))<=0.0001){
temp=0;
c.x=a[i].x,c.y=a[i].y;
}
}
//cout<<temp<<" "<<c.x<<" "<<c.y<<endl;
if(b[0].y>b[1].y){
if(temp==0){
if(c.x>b[0].x) cout<<"left"<<endl;
else cout<<"right"<<endl;
}
else{
if(c.x>b[1].x) cout<<"right"<<endl;
else cout<<"left"<<endl;
}
}
else if(b[0].y<b[1].y){
if(temp==1){
if(c.x<b[1].x) cout<<"right"<<endl;
else cout<<"left"<<endl;
}
else{
if(c.x>b[0].x) cout<<"right"<<endl;
else cout<<"left"<<endl;
}
}
else{
if(temp==0){
if(c.y<b[0].y) cout<<"right"<<endl;
else cout<<"left"<<endl;
}
else{
if(c.y>b[0].y) cout<<"right"<<endl;
else cout<<"left"<<endl;
}
}
}
return 0;
}
A、Clam and Fish(贪心)
题意:
0代表的没鱼没蚯蚓
1代表的没鱼有蚯蚓
2代表的有鱼没蚯蚓
3代表的有鱼有蚯蚓
求最多能得到多少条鱼。
思路:
有鱼钓鱼,没鱼就做鱼饵。
最后加上剩下的鱼饵的一半,即贪心取最后一半的鱼饵,另外一半钓鱼。
代码:
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define eps 1e-10
#define io std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int manx=2e6+5;
const int N=5e3+5;
const int mod=1e9+7;
int main(){
io; ll p; cin>>p;
while(p--){
ll cnt=0,ans=0,n; string s; cin>>n>>s;
for(auto x: s){
if(x=='0'&&cnt) ans++,--cnt;
if(x=='1') ++cnt;
if(x=='3'||x=='2') ++ans;
}
ans+=cnt/2;
cout<<ans<<endl;
}
return 0;
}

京公网安备 11010502036488号