# 1004

## 代码

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int a[100005]={0};
int b[100005]={0};
int main()
{
int t;int n,p;
scn(t);
//init();
while(t--){
scn(n);scn(p);
ll ans=0;
for(int i=1;i<=n;i++){
scn(a[i]);
a[i]%=p;
b[i]=b[i-1]+a[i];
}
for(int i=1;i<=n;i++){
if(a[i]==0) {
//cout<<ans<<" "<<b[i]<<" !!! "<<i<<endl;
}
else{
if((b[i]-b[j])%p==0) {
//cout<<ans<<" "<<b[i]<<" "<<b[j]<<endl;
ans++;
break;
}
}
}
}
printf("%lld\n",ans);
}
return 0;
}

# 1008

## 代码

#include<bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false),cin.tie(0);
#define ll long long
#define inf 0x3f3f3f3f
const int N=1e5+5;
//set<string>b;
//set<string>::iterator it;
const double eps=1e-8;
const double pi=acos(-1.0);
int dcmp(double x)
{
if(fabs(x)<eps) return 0;
else if(x>0) return 1;
return -1;
}
struct Point
{
double x,y;
Point(){}
Point(double a,double b)
{
x=a;
y=b;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
double distance(Point p)
{
return hypot(x-p.x,y-p.y);
}
{
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point a,Point b)
{
s=a;
e=b;
}
double getDis(Point a)
{
return fabs((a-s)^(e-s))/s.distance(e);
}
};
double L,x,y,vx,vy,h;
Point A,B,C,S,v1,v2,v3;
Line AB,AC,BC;
ll k;
void init()
{
h=L*sqrt(3.0)/2.0;
v1=Point(vx,vy);
v2=v1.Rotate(2.0*pi/3);
v3=v1.Rotate(-2.0*pi/3);
S=Point(x,y);
A=Point(0,h);
B=Point(L/2.0,0);
C=Point(-L/2.0,0);
AB=Line(A,B);
AC=Line(A,C);
BC=Line(B,C);
}
ll Num(double dy)
{
ll ans=0;
if(dy>=0) ans+=(ll)(dy/h);
else ans+=(ll)(-dy/h)+1;
return ans;
}
bool judge(double t)
{
ll ans=0;
double dy;
dy=BC.getDis(S)+v1.y*t;
ans+=Num(dy);
dy=AC.getDis(S)+v2.y*t;
ans+=Num(dy);
dy=AB.getDis(S)+v3.y*t;
ans+=Num(dy);
return ans>=k;
}
int main()
{
IO;
int T;
double l,r,mid;
cin>>T;
while(T--)
{
cin>>L>>x>>y>>vx>>vy>>k;
init();
l=0.0;r=1e10;
while((r-l)>=1e-4)
{
mid=(r+l)/2.0;
if(judge(mid)) r=mid;
else l=mid;
}
cout<<fixed<<setprecision(10)<<mid<<endl;
}
return 0;
}

# 1009

## 代码

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 5;
const int maxn = 3e5 + 5;
map<ll, ll> mp;
int pre[maxn], vis[30];
char dp[maxn];
vector<ll> vec;
typedef pair<char, int> p;
stack<p> q;
ll a[maxn], sum[maxn];
char pc[maxn];
char s[maxn];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
int t;
cin >> t;
while (t--)
{
while (!q.empty())
q.pop();
scanf("%s", s + 1);
int n = strlen(s + 1);
for (int i = 1; i <= n; i++) //得到未匹配的字符串pc
{
pc[i] = s[i];
if (s[i] == '(')
q.push(p(s[i], i));
else if (s[i] != '*')
{
if (!q.empty())
pc[q.top().second] = pc[i] = '!', q.pop();
}
}
bool fla = false;
int lp = 0, rp = 0, k = n + 1;
for (int i = 1; i <= n; i++)//检查）的数量并查看是否可以构造出合格的括号
{
if (pc[i] == '*')
lp++;
if (pc[i] == ')')
{
if (!lp)
{
fla = true;
break;
}
rp++, lp--;
}
if (pc[i] == '(')
{
k = i;
break;
}
}
for (int i = 1; i <= n; i++)//若可以成功最早出现的*变为(,为匹配的)--
{
if (pc[i] == '*' && rp)
s[i] = '(', rp--;
}
lp = 0, rp = 0;//以上同理
for (int i = n; i >= k; i--)
{
if (pc[i] == '*')
rp++;
if (pc[i] == '(')
{
if (!rp)
{
fla = true;
break;
}
rp--, lp++;
}
}
for (int i = n; i >= k; i--)
{
if (pc[i] == '*' && lp)
s[i] = ')', lp--;
}
if (fla)
puts("No solution!");
else
{
for (int i = 1; i <= n; i++)
{
if (s[i] != '*')
putchar(s[i]);
}
puts("");
}
}
}

# 1005

## 代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
scanf("%d%d",&n,&k);
int sum = n*(n+1)/2;
if(sum%n==k){
if(n%2==1){
for(int i=1; i<=(n-1)/2; ++i){
printf("%d %d ",i,n-i);
}
printf("%d\n",n);
}
else{
for(int i=1; i<=(n-2)/2; ++i){
printf("%d %d ",i,n-i);
}
printf("%d %d",n/2,n);
}
}
else
printf("-1\n");
return 0;
}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

For the brave

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
08-02 792
08-25 512

07-29 156
07-24 95
09-01 794