#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<cstring>
#define ll long long
using namespace std;
int a[9];
int main()
{
for(int i=0;i<9;i++)
a[i]=i+1;///数字1-9
int n,x,b,c,ans=0;
scanf("%d",&n);
do
{
x=0;
for(int i=0;i<6;i++)/// n<= 1000000
{
x=x*10+a[i];
if(x<n)
{
int idx=(8-i)/2;///对x后面的数位折半 确保b>c
while((i+idx)<8)
{
b=0;c=0;
int j;
for(j=i+1;j<=(i+idx);j++)
b=b*10+a[j];
for(;j<9;j++)
c=c*10+a[j];
if(b%c==0 && b>c && n==(x+b/c) )
ans++;
idx++;
}
}
}
}while(next_permutation(a,a+9));///对数组a里下标为0到下标为8这九个数全排列
printf("%d\n",ans);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int r,c,k;
int mp[15][15];
bool vis[15][15];
int ans = 9999999; //最少的格子数
int all;
int dir[4][2] = {{-1,0},{0,-1},{1,0},{0,1}};
void dfs(int x, int y, int cnt, int sum){
// cnt是已走过格子数,sum已走过格子数字总和
if(x < 0 || x >= r || y < 0 || y >= c || vis[x][y]){
return;
}
if(sum + mp[x][y] == all / 2){
ans = min(ans,cnt+1);
return;
}
vis[x][y] = true;
for(int i = 0; i < 4; i++){
dfs(x+dir[i][0],y+dir[i][1],cnt+1,sum+mp[x][y]);
}
vis[x][y] = false;
}
int main(){
cin >> c >> r;
for(int i = 0; i < r; i++){
for(int j = 0 ; j < c; j++){
cin >> mp[i][j];
all += mp[i][j];
}
}
if(all % 2 != 0){
cout << 0 << endl;
return 0;
}
dfs(0,0,0,0);
cout << ans << endl;
return 0;
}
//找最典型规律最简单
#include<stdio.h>
#include<string.h>
int main()
{
char st[1005]={0};
char ed[1005]={0};
int f[1005];
int count=0,i=0;
scanf("%s %s",st,ed);
while(st[i]!='\0')
{
if(st[i]==ed[i])
{
f[i]=0;
}
else
{
f[i]=1;
}
i++;
}
i=0;
int start=-1;
while(st[i]!='\0')
{
if(f[i]==1)
{
if(start==-1)
{
start=i;
}
else
{
count+=i-start;
start=-1;
}
}
i++;
}
printf("%d",count);
return 0;
}
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <limits.h>
#include <map>
using namespace std;
int n,arr[50005];
void f() {
int res = n;
for (int i = 0; i < n; i++) {
int ma = arr[i];
int mi = arr[i];
for (int j = i + 1; j < n; j++) {
ma = max(ma, arr[j]);
mi = min(mi, arr[j]);
if (ma - mi == j - i) {
res++;
}
}
}
cout << res << endl;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
f();
return 0;
}
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
struct Edge{
int to,next,val;
};
long long max_len;
int max_num,n;
void bfs(int s,long long *dis,Edge *e,int *h){
//memset(dis,-1,sizeof(dis));
int top,i;
for(i=1;i<=n;i++){
dis[i]=-1;
}
queue<int> q;
q.push(s);
//vis[s]=true;
dis[s]=0;
while(!q.empty()){
//cout<<max_num<<endl;
top=q.front();
q.pop();
//vis[top]=false;
for(i=h[top];i+1;i=e[i].next){
//cout<<i<<endl;
if(dis[e[i].to]==-1){
//vis[e[i].to]=true;
dis[e[i].to]=dis[top]+e[i].val;
if(dis[e[i].to]>max_len){
max_len=dis[e[i].to];
max_num=e[i].to;
}
q.push(e[i].to);
}
}
}
}
int main(){//树的直径问题
//freopen("D://INPUT.txt","r",stdin);
scanf("%d",&n);
Edge *e=new Edge[n*2+1];
int *h=new int[n+1];
long long *dis=new long long[n+1];
//bool *vis=new vis[n+1];
int i,num=0;
int nn=n-1,u,v,val;
//memset(h,-1,sizeof(h));
for(i=1;i<=n;i++){
h[i]=-1;
}
for(i=0;i<nn;i++){//建邻接表
scanf("%d %d %d",&u,&v,&val);
e[num].to=v;
e[num].val=val;
e[num].next=h[u];
h[u]=num++;
e[num].to=u;
e[num].val=val;
e[num].next=h[v];
h[v]=num++;
}
max_len=-1;
max_num=1;
bfs(1,dis,e,h);
//cout<<max_num<<endl;
//cout<<max_len<<endl;
bfs(max_num,dis,e,h);
cout<<max_len*(max_len+21)/2<<endl;
delete []e;
delete []h;
delete []dis;
return 0;
}
#include <stdio.h>
main()
{
int a,b,c,s;
do
{
scanf("%d%d%d", &a,&b,&c);
}
while(a>30&&b>30&&c>30);
s=f1(a,b);
// printf("%d\n",s);
s=f1(s,c);
printf("%d\n",s);
return 0;
}
int f1(int a,int b)
{
int t,m;
int c;
if (a < b)
{
t = a;
a = b;
b = t;
}
m = a * b;
c = a % b;
while (c != 0)
{
a = b;
b = c;
c = a % b;
}
return m/b;
}
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
const double PI = atan(1.0) * 4;
const double EPS = 1e-10;
class Point {
public:
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator - (const Point &r) const { return Point(x-r.x, y-r.y); }
Point operator + (const Point &r) const { return Point(x+r.x, y+r.y); }
Point &operator += (const Point &r) { x += r.x; y += r.y; return *this; }
Point &operator *= (double m) { x *= m; y *= m; return *this; }
Point pOfRotate(double angle) const {
double cosA = cos(angle);
double sinA = sin(angle);
return Point(cosA*x-sinA*y, sinA*x+cosA*y);
}
Point pOfRotate90() const { return Point(-y, x); }
double length() const { return sqrt(x*x+y*y); }
Point pOfNormal() const {
double len = length();
return Point(x/len, y/len);
}
double angle() const { return atan2(y, x); }
};
ostream & operator <<(ostream &os, const Point &v)
{
os << "(" << v.x << "," << v.y << ")";
return os;
}
class Segment;
class Circle;
class Seg {
public:
virtual double getLeft() const = 0;
virtual double getRight() const = 0;
virtual double getY(double x) const = 0;
virtual double getLength(double x1, double x2) const = 0;
virtual void intersect(Seg *r) const = 0;
virtual void intersect(const Segment &v) const = 0;
virtual void intersect(const Circle &v) const = 0;
bool contains(double x) const { return x>=getLeft() && x<=getRight(); }
virtual void acceptPrint(ostream &os) const = 0;
};
ostream & operator <<(ostream &os, const Seg &v)
{
v.acceptPrint(os);
return os;
}
Point intersectRet[4];
int tIntersectRet;
class Segment : public Seg {
public:
Point a, b;
Segment &moveLeft(double dis)
{
Point tmp = ((b-a).pOfRotate90().pOfNormal() *= dis);
a += tmp;
b += tmp;
return *this;
}
virtual double getLeft() const { return a.x; }
virtual double getRight() const { return b.x; }
virtual double getY(double x) const {
return (x-a.x)*(b.y-a.y)/(b.x-a.x)+a.y;
}
virtual double getLength(double x1, double x2) const {
return (x2-x1) * (b-a).length() / (b.x-a.x);
}
virtual void intersect(Seg *r) const {
r->intersect(*this);
}
virtual void intersect(const Segment &v) const {
tIntersectRet = 0;
double ang = (b-a).angle();
Point c = (v.a-a).pOfRotate(-ang);
Point d = (v.b-a).pOfRotate(-ang);
double di = (b-a).length();
if (!((c.y>0&&d.y<0) || (c.y<0&&d.y>0)))
return ;
double x = (d.x-c.x) * (-c.y) / (d.y-c.y) + c.x;
if (x<0 || x>di)
return ;
Point ret = Point(x,0).pOfRotate(ang)+a;
intersectRet[tIntersectRet++] = ret;
}
virtual void intersect(const Circle &v) const;
virtual void acceptPrint(ostream &os) const {
os << a << "-" << b;
}
};
class Circle : public Seg {
public:
Point c;
double r;
virtual double getLeft() const { return c.x - r; }
virtual double getRight() const { return c.x + r; }
virtual double getY(double x) const {
double y2 = r * r - (c.x - x) * (c.x - x);
if (y2<0) y2 = 0;
return c.y + sqrt(y2);
}
virtual double getLength(double x1, double x2) const {
x1 -= c.x; x2 -= c.x;
double a1 = Point(x1, sqrt(abs(r*r-x1*x1))).angle(), a2 = Point(x2, sqrt(abs(r*r-x2*x2))).angle();
return (a1-a2) * r;
}
virtual void intersect(Seg *r) const {
r->intersect(*this);
}
virtual void intersect(const Segment &v) const {
tIntersectRet = 0;
Point a = v.a - c;
Point b = v.b - c;
double ang = (b-a).angle();
Point nA = a.pOfRotate(-ang);
Point nB = b.pOfRotate(-ang);
double y = nA.y;
if (y>r || y<-r)
return ;
double x = sqrt(r*r - y*y);
if (x>=nA.x && x<=nB.x)
intersectRet[tIntersectRet++] = Point(x, y).pOfRotate(ang) + c;
if (-x>=nA.x && -x<=nB.x)
intersectRet[tIntersectRet++] = Point(-x, y).pOfRotate(ang) + c;
}
virtual void intersect(const Circle &v) const {
tIntersectRet = 0;
Point p = v.c - c;
double d = p.length();
if (d > r + v.r || d==0)
return ;
double x = (r*r - v.r*v.r + d*d) / (2*d);
if (x <= r)
{
double y = sqrt(abs(r*r - x*x));
double ang = p.angle();
intersectRet[tIntersectRet++] = Point(x,y).pOfRotate(ang) + c;
intersectRet[tIntersectRet++] = Point(x,-y).pOfRotate(ang) + c;
}
}
virtual void acceptPrint(ostream &os) const {
os << c << "," << r;
}
};
void Segment::intersect(const Circle &v) const {
v.intersect(*this);
}
int n;
Point inps[MAXN];
vector<Seg *> segs;
vector<double> spes;
double radius = 1;
void input()
{
scanf("%d%lf", &n, &radius);
for (int i = 0; i < n; ++i)
{
double x, y;
scanf("%lf%lf", &x, &y);
inps[i] = Point(x, y);
}
}
void process()
{
segs.clear();
spes.clear();
for (int i = 1; i + 1 < n; ++i)
{
Circle *tmp = new Circle;
tmp->c = inps[i];
tmp->r = radius;
segs.push_back(tmp);
}
for (int i = 0; i + 1 < n; ++i)
{
Segment *tmp = new Segment;
tmp->a = inps[i];
tmp->b = inps[i+1];
tmp->moveLeft(radius);
segs.push_back(tmp);
}
for (int i = 0; i < (int)segs.size(); ++i)
{
spes.push_back(segs[i]->getLeft());
spes.push_back(segs[i]->getRight());
}
for (int i = 0; i < (int)segs.size(); ++i)
{
for (int j = i+1; j < (int)segs.size(); ++j)
{
segs[i]->intersect(segs[j]);
if (tIntersectRet > 0)
{
for (int id = 0; id < tIntersectRet; ++id)
{
spes.push_back(intersectRet[id].x);
}
}
}
}
sort(spes.begin(), spes.end());
double pre = spes[0];
const double NONE = 1e30;
double preEnd = NONE;
double totalLen = 0;
for (int i = 1; i < (int)spes.size(); ++i)
{
if (spes[i]-pre < EPS)
continue;
double cur = (pre+spes[i]) / 2;
if (cur>=inps[0].x && cur<=inps[n-1].x)
{
double MY = -NONE;
int who;
for (int j = 0; j < (int)segs.size(); ++j)
{
if (!segs[j]->contains(cur))
continue;
double y = segs[j]->getY(cur);
if (y > MY)
{
MY = y;
who = j;
}
}
if (preEnd != NONE)
{
double LY = segs[who]->getY(pre);
totalLen += abs(preEnd-LY);
}
double len = segs[who]->getLength(pre, spes[i]);
if (len < 0)
printf("Error!\n");
totalLen += len;
preEnd = segs[who]->getY(spes[i]);
}
pre = spes[i];
}
printf("%0.2lf\n", totalLen);
for (int i = 0; i < (int)segs.size(); ++i)
delete segs[i];
segs.clear();
}
int main()
{
input();
process();
return 0;
}
比如:
输入
60
输出
-1
#include <stdio.h>
int main ()
{
int a,b,c,d,e,f;
int flag=0;
int n;
scanf("%d",&n);
for(int i=10000;i<999999;i++)
{
if(i/100000==0)
{
a=i%10;
b=((i-a)/10)%10;
c=((((i-a)/10)-b)/10)%10;
d=((((((i-a)/10)-b)/10)-c)/10)%10;
e=((((((((i-a)/10)-b)/10)-c)/10)-d)/10)%10;
int sum= a*10000+b*1000+c*100+d*10+e*1;
if(sum==i && a+b+c+d+e==n)
{
printf("%d\n",sum);
flag=1;
}
}
else
{
a=i%10;
b=((i-a)/10)%10;
c=((((i-a)/10)-b)/10)%10;
d=((((((i-a)/10)-b)/10)-c)/10)%10;
e=((((((((i-a)/10)-b)/10)-c)/10)-d)/10)%10;
f=((((((((((i-a)/10)-b)/10)-c)/10)-d)/10)-e)/10)%10;
int sum= a*100000+b*10000+c*1000+d*100+e*10+f;
if(sum==i && a+b+c+d+e+f==n)
{
printf("%d\n",sum);
flag=1;
}
}
}
if(flag==0)
printf("-1");
return 0;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
int x,y,d;
} s[100000+5];
int n,f[10000+5];
bool cmp(node a,node b)
{
return a.d>b.d;
}
void Set()
{
for (int i=1; i<=n; i++)
f[i]=i;
}
int Find(int x)//查找根节点
{
if (f[x]==x)
return x;
return f[x]=Find(f[x]);
}
bool Union(int x,int y)
{
x=Find(x);
y=Find(y);
if (x!=y)
{
f[x]=y;
return 1;
}
return 0;
}
int main()
{
int m;
while (~scanf("%d%d",&n,&m))
{
for (int i=1; i<=m; i++)
{
scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].d);
}
sort(s+1,s+m+1,cmp);
Set();
int pre=-1,ans=0;//表示前一次是在第几天进行反抗的
for (int i=1; i<=m; i++)
{
int way=Union(s[i].x,s[i].y);//way=0表示之前有桥,不需要在建桥
if (way==1&&s[i].d!=pre)
{
ans++;
pre=s[i].d;
}
}
cout<<ans<<endl;
}
return 0;
}
#include <stdio.h>
int main()
{
int n, k, T;
long long sum = 1, t=1, a=1;
scanf("%d%d%d", &n, &k, &T);
for(int i = 1; i < T; ++i)
{
t = (((a+a+n-1)*n/2)+t)%k;
sum += t;
a += n;
}
printf("%lld\n", sum);
return 0;
}