第一题
#include <iostream>
using namespace std;
int INF=1e5+5;
bool is(char ch)
{
return ch==','||ch=='.'||ch=='!'||ch=='?';
}
int solve(string &s,int L,int R,int x)
{
int count=0;
while(R>=L)
{
count++;
int newL=L+x;
while(newL>L&&is(s[newL]))
newL--;
if(newL==L)
return INF;
L=newL;
}
return count;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int x,y;
string s;
cin>>x>>y>>s;
x=y/x;
int len=s.length();
int sum=0,pre=0;
for(int i=0;i<len-1;i++) if(s[i]=='\\'&&s[i+1]=='n')
{
sum+=solve(s,pre,i-1,x);
pre=i+2;
}
sum+=solve(s,pre,len-1,x);
if(sum>=INF)
cout<<"impossible"<<endl;
else
cout<<sum<<endl;
}
return 0;
}
/*
3
2 5
hello,world!
1 1
hello,world!
3 10
NoNewLine\nNew!\nLine
*/
第二题
#include <iostream>
#include<queue>
using namespace std;
int INF=1e5+5;
void bfs(vector<int> G[],int ans[])
{
queue<int> q;
for(int i=0;i<26;i++)
if(ans[i]==1)
q.push(i);
while(!q.empty())
{
int t=q.front();
q.pop();
for(int i=0;i<(int)G[t].size();i++)
{
int v=G[t][i];
if(ans[v]>ans[t]+1)
{
ans[v]=ans[t]+1;
q.push(v);
}
}
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N,M;
vector<int> G[26];
int ans[26];
for(int i=0;i<26;i++)
{
G[i].clear();
ans[i]=1;
}
cin>>N;
while(N--)
{
char x,y;
cin>>x>>y;
G[x-'a'].push_back(y-'a');
}
cin>>M;
while(M--)
{
char x;
cin>>x;
ans[x-'a']=INF;
}
bfs(G,ans);
//for(int i=0;i<26;i++) cout<<ans[i]<<" ";
string s;
cin>>s;
int sum=0,len=s.length();
for(int i=0;i<len;i++)
sum+=ans[s[i]-'a'];
if(sum>=INF)
printf("-1\n");
else
printf("%d\n",sum);
}
return 0;
}
/*
2
5
a b
b c
x c
e f
f x
2
b c
helloworldabc
5
a b
b c
x c
e f
f x
4
b c f x
helloworldabcsfx
*/
第三题
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
double esp=1e-7;
typedef struct node
{
double x, y;
}NODE;
inline NODE Vector(NODE A, NODE B);
inline double dis2(NODE a, NODE b);
double angleA(NODE O1, double r1, NODE O2, double r2);
double angleT(NODE O1, NODE O2);
NODE polar(double a, double r);
void getPoint(vector<NODE> &p, NODE O1, NODE O2, int r)
{
double r1=r, r2=r;
//cin >> O1.x >> O1.y >> r1;
//cin >> O2.x >> O2.y >> r2;
long long dx=abs(O1.x-O2.x)+0.5;
long long dy=abs(O1.y-O2.y)+0.5;
//cout<<dx*dx+dy*dy<<" ****"<<2*r*2*r<<endl;
if (dx*dx+dy*dy>2*r*2*r)
{
return;//cout << "不存在交点" << endl;
}
double t = angleT(O1, O2);
double a = angleA(O1, r1, O2, r2);
NODE polar1 = polar(t+a,r1);
NODE polar2 = polar(t-a, r1);
NODE x1 = {O1.x+polar1.x,O1.y+polar1.y};
NODE x2 = {O1.x+polar2.x,O1.y+polar2.y};
p.push_back(x1);
p.push_back(x2);
}
NODE polar(double a, double r)
{
return{ r*cos(a), r*sin(a) };
}
double angleA(NODE O1, double r1, NODE O2,double r2) //求角a
{
return acos((r1*r1+dis2(O1,O2)-r2*r2)/(2*r1*sqrt(dis2(O1,O2)))); //余弦定理
}
double angleT(NODE O1,NODE O2) //求角t
{
NODE O1O2 = Vector(O1, O2);
return atan2(O1O2.y, O1O2.x); //atan2(double y,double x) 计算向量O1O2与x轴的夹角 范围(-pi,pi]
}
inline NODE Vector(NODE A, NODE B)
{
return{ B.x - A.x, B.y - A.y };
}
inline double dis2(NODE a, NODE b)
{
return (b.x-a.x)*(b.x-a.x) + (b.y-a.y)*(b.y-a.y);
}
/*
3
4 0.5
2.0 2.0
3.0 2.0
2.5 2.5
2.5 1.5
3 1.0
0.0 0.0
100.0 100.0
200.0 200.0
3 1.0
0.0 0.0
0.5 0.0
100.0 100.0
3
2 0.5
2.0 2.0
3.0 2.0
*/
int solve( NODE points[], NODE a,int n,double r)
{
int rt=0;
for( int i=0;i<n;i++)
if(dis2(points[i], a)<=r*r+esp)
rt++;
return rt;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int n,r;
double doubler;
cin>>n>>doubler;
r=doubler*10+0.5;
NODE points[105];
for(int i=0;i<n;i++)
{
cin>>points[i].x>>points[i].y;
points[i].x=points[i].x*10+0.5;
points[i].y=points[i].y*10+0.5;
}
vector<NODE> p;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(!(points[i].x==points[j].x&&points[i].y==points[j].y))
getPoint(p,points[i],points[j],r);
// for(int i=0;i<p.size();i++)
int MAX=1;
for(int i=0;i<p.size();i++)
MAX=max(MAX,solve(points,p[i],n,r));
cout<<MAX<<endl;
}
}