diff --git a/CSU/1120.cpp b/CSU/1120.cpp new file mode 100644 index 0000000..238022c --- /dev/null +++ b/CSU/1120.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + +#include +#include +using namespace std; + +namespace LCIS_INT_LESSMEM +{ + const int MAXL=1024; + int ldp[MAXL]; + int deal(int* pa,int na,int *pb,int nb) + { + memset(ldp,0,MAXL*sizeof(int)); + for(int i=1;i<=na;i++) + { + int k=0; + for(int j=1;j<=nb;j++) + { + if(pa[i]>pb[j]) k=max(k,ldp[j]); + else if(pa[i]==pb[j]) + { + ldp[j]=k+1; + } + } + } + int ans = 0; + for(int i = 1; i <= nb; i++) ans = max(ans, ldp[i]); + return ans; + } +} + +/// CSUOJ 1120 +int a[1024]; +int b[1024]; +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int na; + scanf("%d",&na); + for(int i=1;i<=na;i++) + { + scanf("%d",&a[i]); + } + int nb; + scanf("%d",&nb); + for(int i=1;i<=nb;i++) + { + scanf("%d",&b[i]); + } + printf("%d\n",LCIS_INT_LESSMEM::deal(a,na,b,nb)); + } + return 0; +} diff --git a/HDOJ/2854.cpp b/HDOJ/2854.cpp new file mode 100644 index 0000000..2b914e1 --- /dev/null +++ b/HDOJ/2854.cpp @@ -0,0 +1,66 @@ +#include +#include +#include + +using namespace std; + +/* +int main() +{ + /// Test Program + int N; + for(N=1;N<5005;N++) + { + bool isOK=false; + for(int A=1;A<=N;A++) + { + for(int B=1;B<=N;B++) + { + if((A*A*B+1)%N==0) + { + if((A*A+B)%N==0) + { + //printf("A=%d B=%d\n",A,B); + isOK=true; + } + else + { + goto OUT; + } + } + } + } + if(isOK) + { + printf("%d,",N); + } + OUT:continue; + } +} +//*/ +int a[]={1,2,3,4,5,6,8,10,12,15,16,20,24,30,40,48,60,80,120,240}; +const int sza=sizeof(a)/sizeof(int); + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int x; + scanf("%d",&x); + bool isFound=false; + for(int i=0;i +#include +#include +using namespace std; + +char mp[1024][1024]; + +int cat=0; +int girl=0; + +void dp_girl(int i,int j,int step) +{ + switch(step) + { + case 1:if(mp[i][j]!='i') return;break; + case 2:if(mp[i][j]!='r') return;break; + case 3:if(mp[i][j]!='l') return;else ++girl;return;break; + } + dp_girl(i+1,j,step+1); + dp_girl(i,j+1,step+1); + dp_girl(i-1,j,step+1); + dp_girl(i,j-1,step+1); +} + +void dp_cat(int i,int j,int step) +{ + switch(step) + { + case 1:if(mp[i][j]!='a') return;break; + case 2:if(mp[i][j]!='t') return;else ++cat;return; + } + dp_cat(i+1,j,step+1); + dp_cat(i,j+1,step+1); + dp_cat(i-1,j,step+1); + dp_cat(i,j-1,step+1); +}//// +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int n,m; + scanf("%d %d",&n,&m); + cat=0; + girl=0; + memset(mp,0,1024*1024); + for(int i=1;i<=n;i++) + { + scanf("%s",&mp[i][1]); + } + for(int i=1;i<=n;i++) + { + for(int j=1;j<=m;j++) + { + if(mp[i][j]=='g') dp_girl(i,j,0); + else if(mp[i][j]=='c') dp_cat(i,j,0); + } + } + printf("%d %d\n",girl,cat); + } + return 0; +} diff --git a/NYOJ/38.cpp b/NYOJ/38.cpp new file mode 100644 index 0000000..4a02f3b --- /dev/null +++ b/NYOJ/38.cpp @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include +using namespace std; + +#define MAXPOINT 512 + +//#define dprintf(A,B...) printf(A,##B) +#define dprintf(A,B...) + +int groupid[MAXPOINT]; + +struct EDGE +{ + int u,v; + int w; +}; + +bool cmp_d(const EDGE& a,const EDGE& b) +{ + if(a.w==b.w) + { + if(a.u==b.u) + { + return a.v vec; + EDGE tmp; + for(int i=0;itmp.v) + swap(tmp.u,tmp.v); + vec.push_back(tmp); + } + sort(vec.begin(),vec.end(),cmp_d); + for(int i=0;i dpos; + int dtmp; + for(int i=0;i +#include +#include +#include +#include +using namespace std; +const int maxn=505; +const int INF=0x3f3f3f3f; +int map[maxn][maxn]; +int dis[maxn]; +int vis[maxn]; +int N;//N组测试数据 +int V;//点的数量 +int E;//边的数量 +int min_num;//最小外接花费 +void init() +{ + scanf("%d%d",&V,&E); + for(int i=0; i<=V; i++)//初始化图 + for(int j=0; j<=V; j++) + i==j?map[i][j]=0:map[i][j]=INF; + while(E--)//建图 + { + int a,b,c; + scanf("%d%d%d",&a,&b,&c); + map[a][b]=c;//无向图 + map[b][a]=c; + } + min_num=INF; + for(int i=1; i<=V; i++) + { + int x; + scanf("%d",&x); + min_num=min(min_num,x);//生成树连接到外界的最小花费 + dis[i]=map[i][1];//从1开始构造最小生成树 + } + memset(vis,0,sizeof(vis)); + vis[1]=1;//0代表是外界 +} +void Prim() +{ + int min_cost=0;//初始化最小花费 + for(int i=1; idis[j]) + { + point_minn=j; + minn=dis[j]; + } + if(minn==INF) + break; + min_cost+=dis[point_minn]; + vis[point_minn]=1; + for(int j=1; j<=V; j++) + if(vis[j]==0&&dis[j]>map[point_minn][j]) + dis[j]=map[point_minn][j]; + } + printf("%d\n",min_cost+min_num); +} +int main() +{ + scanf("%d",&N); + while(N--) + { + init(); + Prim(); + } + return 0; +} diff --git a/NYOJ/38_张云聪.cpp b/NYOJ/38_张云聪.cpp new file mode 100644 index 0000000..bf046fc --- /dev/null +++ b/NYOJ/38_张云聪.cpp @@ -0,0 +1,71 @@ + +#include +#include +#include +#include +#include +#include +using namespace std; +#define CLR(arr,val) memset(arr,val,sizeof(arr)) +struct Node +{ + Node(){} + Node(int num,int len):len(len),num(num){} + int len,num; +}; +bool operator<(const Node& n1,const Node& n2) +{ + return n1.len>n2.len; +} +const int MAX=510; +const int MAXE=250000; +int Head[MAX],Next[MAXE],Num[MAXE],Len[MAXE]; +int Dis[MAX],top; +void add(int u,int v,int len) +{ + Num[top]=v; + Next[top]=Head[u]; + Len[top]=len; + Head[u]=top++; +} +bool InQ[MAX]; +int main() +{ + //freopen("input.txt","r",stdin); + priority_queue q; + int t,m,n,a,b,l; + scanf("%d",&t); + while(t--) + { + top=0;CLR(Head,-1); + CLR(Dis,0x3f); + scanf("%d%d",&m,&n); + for(int i=0;i!=n;i++) + { + scanf("%d%d%d",&a,&b,&l); + add(a-1,b-1,l);add(b-1,a-1,l); + } + Dis[0]=0; + q.push(Node(0,0)); + while(!q.empty()) + { + Node t=q.top();q.pop(); + if(Dis[t.num]!=t.len) continue; + for(int i=Head[t.num];i!=-1;i=Next[i]) + { + if(Dis[Num[i]]>Len[i]) + { + Dis[Num[i]]=Len[i]; + q.push(Node(Num[i],Len[i])); + } + } + } + int minl=0x3f3f3f3f; + for(int i=0;i!=m;i++) + { + scanf("%d",&l); + minl=min(minl,l); + } + printf("%d\n",accumulate(Dis,Dis+m,0)+minl); + } +} diff --git a/QUSTOJ/1026.cpp b/QUSTOJ/1026.cpp new file mode 100644 index 0000000..d3083f2 --- /dev/null +++ b/QUSTOJ/1026.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +using namespace std; +int n; +double A[110][110]; +int main() +{ + scanf("%d",&n);n++; + for(int i=1;i +#include +#include +#include +using namespace std; +//Written by Coffee. 判断素数 +bool isPrime(int num) +{ + if (num == 2 || num == 3) + { + return true; + } + if (num % 6 != 1 && num % 6 != 5) + { + return false; + } + for (int i = 5; i*i <= num; i += 6) + { + if (num % i == 0 || num % (i+2) == 0) + { + return false; + } + } + return true; +} + +int main() +{ + int n,k; + vector vec; + scanf("%d %d",&n,&k); + int tmp; + for(int i=0;i +using namespace std; +int main() +{ + int a,b,mx=0; + int i; + int m,n,v[61]= {0},p[61]= {0},q; + int v1[61]= {0},v2[61]= {0},p1[61]= {0},p2[61]= {0}; + int f[50001]= {0}; + cin>>m>>n; + m/=10; + for(i=1; i<=n; i++) + { + cin>>a>>b>>q; + a/=10; + if(q!=0) + { + if(v1[q]==0) + { + v1[q]=a; + p1[q]=b; + } + else + { + v2[q]=a; + p2[q]=b; + } + } + else + { + v[i]=a; + p[i]=b; + } + } + for(int i=1; i<=n; i++) + for(int j=m; j>=v[i]; j--) + { + f[j]=max(f[j],f[j-v[i]]+v[i]*p[i]); + if(j-v1[i]-v[i]>=0)f[j]=max(f[j],f[j-v1[i]-v[i]]+v1[i]*p1[i]+v[i]*p[i]); + if(j-v2[i]-v[i]>=0)f[j]=max(f[j],f[j-v2[i]-v[i]]+v2[i]*p2[i]+v[i]*p[i]); + if(j-v1[i]-v2[i]-v[i]>=0)f[j]=max(f[j],f[j-v1[i]-v2[i]-v[i]]+v1[i]*p1[i]+v2[i]*p2[i]+v[i]*p[i]); + mx=max(f[j],mx); + } + cout< +#include +#include +#include +#include +using namespace std; +const int maxn = 205; +const double eps = 1e-8; +typedef int typef; +typedef int typec; +#define inff 0x0fffffff +#define infc 0x0fffffff +#define V 500 +#define E 200000 +struct network +{ + int nv, ne, pnt[E], nxt[E]; + int vis[V], que[V], head[V], pv[V], pe[V]; + typef flow, cap[E]; typec cost, dis[E], d[V]; + void addedge(int u, int v, typef c, typec w) + { + pnt[ne] = v; cap[ne] = c; + dis[ne] = w; nxt[ne] = head[u]; head[u] = ne++; + pnt[ne] = u; cap[ne] = 0; + dis[ne] = -w; nxt[ne] = head[v]; head[v] = ne++; + } + int mincost(int src, int sink) + { + int i, k, f, r; typef mxf; + for(flow = 0, cost = 0; ; ) + { + memset(pv, -1, sizeof(pv)); + memset(vis, 0, sizeof(vis)); + for(i = 0; i < nv; ++i) d[i] = infc; + d[src] = 0; pv[src] = src; vis[src] = 1; + for(f = 0, r = 1, que[0] = src; r != f; ) + { + i = que[f++]; vis[i] = 0; + if(V == f) f = 0; + for(k = head[i]; k != -1; k = nxt[k]) + if(cap[k] && dis[k]+d[i] < d[pnt[k]]) + { + d[pnt[k]] = dis[k] + d[i]; + if(0 == vis[pnt[k]]) + { + vis[pnt[k]] = 1; + que[r++] = pnt[k]; + if(V == r) r = 0; + } + pv[pnt[k]] = i; pe[pnt[k]] = k; + } + } + if(-1 == pv[sink]) break; + for(k = sink, mxf = inff; k != src; k = pv[k]) + if(cap[pe[k]] < mxf) mxf = cap[pe[k]]; + flow += mxf; cost += d[sink] * mxf; + for(k = sink; k != src; k = pv[k]) + { + cap[pe[k]] -= mxf; cap[pe[k]^1] += mxf; + } + } + return cost; + } + void init(int v) + { + nv = v; ne = 0; + memset(head, -1, 4 * v); + } +} nw; +struct Lich +{ + double x, y, r; + int t; + void input() + { + scanf("%lf %lf %lf %d", &x, &y, &r, &t); + } +} lich[maxn]; +struct Wisp +{ + double x, y; + void input() + { + scanf("%lf %lf", &x, &y); + } +} wisp[maxn]; +struct Tree +{ + double x, y, r; + void input() + { + scanf("%lf %lf %lf", &x, &y, &r); + } +} tree[maxn]; +int T, N, M, K; +int ecnt[maxn]; +double Dot(double dx1, double dy1, double dx2, double dy2) +{ + return dx1 * dx2 + dy1 * dy2; +} +double Dis(double x0, double y0, double x1, double y1, double x2, double y2) +{ + double a, b, c; + if (fabs(x1 - x2) > fabs(y1 - y2)) + { + b = 1.0; + a = b * (y2 - y1) / (x1 - x2); + c = -(a * x1 + b * y1); + } + else + { + a = 1.0; + b = a * (x2 - x1) / (y1 - y2); + c = -(a * x1 + b * y1); + } + return fabs(a * x0 + b * y0 + c) / sqrt(a * a + b * b); +} +bool NoCross(int a, int b) +{ + int i; + for (i = 0; i < K; i++) + { + if (Dot(tree[i].x - lich[a].x, tree[i].y - lich[a].y, wisp[b].x - lich[a].x, wisp[b].y - lich[a].y) > 0.0 && + Dot(tree[i].x - wisp[b].x, tree[i].y - wisp[b].y, lich[a].x - wisp[b].x, lich[a].y - wisp[b].y) > 0.0 && + Dis(tree[i].x, tree[i].y, lich[a].x, lich[a].y, wisp[b].x, wisp[b].y) < tree[i].r + eps) + return false; + } + return true; +} +bool InRound(int i, int j) +{ + double dx = lich[i].x - wisp[j].x; + double dy = lich[i].y - wisp[j].y; + return sqrt(dx * dx + dy * dy) < lich[i].r + eps; +} +void BuildGraph() +{ + int i, j; + for (i = 0; i < N; i++) + { + ecnt[i] = 0; + for (j = 0; j < M; j++) + { + if (InRound(i, j) && NoCross(i, j)) + { + ecnt[i]++; + nw.addedge(i, N + j, 1, 0); + } + } + } + for (i = 0; i < N; i++) + { + for (j = 0; j < ecnt[i]; j++) + nw.addedge(N + M, i, 1, lich[i].t * j); + } + for (i = 0; i < M; i++) + nw.addedge(N + i, N + M + 1, 1, 0); +} +void Solve() +{ + nw.mincost(N + M, N + M + 1); + if (nw.flow != M) + { + printf("-1\n"); + return; + } + int ans = 0; + for (int p = nw.head[N+M]; p != -1; p = nw.nxt[p]) + { + if (nw.cap[p] == 0 && nw.dis[p] > ans) + ans = nw.dis[p]; + } + printf("%d\n", ans); +} +int main() +{ + int i; + for (scanf("%d", &T); T; T--) + { + scanf("%d %d %d", &N, &M, &K); + for (i = 0; i < N; i++) + lich[i].input(); + for (i = 0; i < M; i++) + wisp[i].input(); + for (i = 0; i < K; i++) + tree[i].input(); + nw.init(N + M + 2); + BuildGraph(); + Solve(); + } + return 0; +} diff --git a/QUSTOJ/1342.cpp b/QUSTOJ/1342.cpp new file mode 100644 index 0000000..0d49205 --- /dev/null +++ b/QUSTOJ/1342.cpp @@ -0,0 +1,15 @@ +#include +#define STR_A "6 its factors are 1 2 3 " +#define STR_B "28 its factors are 1 2 4 7 14 " +#define STR_C "496 its factors are 1 2 4 8 16 31 62 124 248 " +#define STR_D "8128 its factors are 1 2 4 8 16 32 64 127 254 508 1016 2032 4064 " +int main() +{ + int n; + scanf("%d",&n); + if(n>=6) puts(STR_A); + if(n>=28) puts(STR_B); + if(n>=496) puts(STR_C); + if(n>=8128) puts(STR_D); + return 0; +} diff --git a/QUSTOJ/1372.cpp b/QUSTOJ/1372.cpp new file mode 100644 index 0000000..8165fb0 --- /dev/null +++ b/QUSTOJ/1372.cpp @@ -0,0 +1,14 @@ +#include +int main() +{ + int n; + scanf("%d",&n); + int f=0; + int m=3; + for(int i=1;i<=n;i++) + { + f=(f+m)%i; + } + printf("%d\n",f+1); + return 0; +} diff --git a/QUSTOJ/1429.java b/QUSTOJ/1429.java new file mode 100644 index 0000000..def7a2a --- /dev/null +++ b/QUSTOJ/1429.java @@ -0,0 +1,24 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + int radix = in.nextInt(); + String s = in.next(); + StringBuffer s2 = new StringBuffer(s).reverse(); + int cnt = 0; + long x = Long.valueOf(s, radix); + while(!s2.toString().equals(s) && cnt <= 30){ + cnt++; + x += Long.valueOf(s2.toString(), radix); + s = Long.toString(x,radix); + s2 = new StringBuffer(s).reverse(); + } + if(cnt > 30){ + System.out.println("Impossible!"); + } else { + System.out.println("STEP=" + cnt); + } + in.close(); + } +} diff --git a/QUSTOJ/1429.pas b/QUSTOJ/1429.pas new file mode 100644 index 0000000..8926fc4 --- /dev/null +++ b/QUSTOJ/1429.pas @@ -0,0 +1,33 @@ +const + step:integer=0; + chars:array[0..15] of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); +var + digit:array[char] of integer; + i,n,g:integer; + m,s:string; + ok:boolean; +begin + for i:=0 to 9 do digit[char(ord('0')+i)]:=i; + for i:=0 to 5 do digit[char(ord('A')+i)]:=i+10; + readln(n); +readln(s); + for i:=1 to length(s) do s[i]:=upcase(s[i]); + repeat + ok:=true; + for i:=1 to length(s) div 2 do + if s[i]<>s[length(s)+1-i] then ok:=false; + if ok then break; + inc(step); + m:=s; g:=0; + for i:=length(m) downto 1 do + begin + s[i]:=chars[(digit[m[i]]+digit[m[length(m)+1-i]]+g) mod n]; + g:=(digit[m[i]]+digit[m[length(m)+1-i]]+g) div n; + end; + if g>0 then s:=chars[g]+s; + until step>=30; + if ok then + writeln('STEP=',step) + else + writeln('Impossible'); +end. diff --git a/QUSTOJ/1433.cpp b/QUSTOJ/1433.cpp new file mode 100644 index 0000000..4c3fc1b --- /dev/null +++ b/QUSTOJ/1433.cpp @@ -0,0 +1,27 @@ +#include +#include +#include +using namespace std; +int main() +{ + int a[1001],n,m,i; + memset(a,0,sizeof(a)); + cin>>n; + int count=0; + for(i=1;i<=n;i++) + { + cin>>m; + a[m]++; + } + for(i=1;i<=1000;i++) + if(a[i]!=0) count++; + cout< +#include + +typedef struct +{ + double L,R; +}INUM; +char str[1024]; +char* format(INUM i) +{ + sprintf(str,"(%.2f%+.2fi)",i.L,i.R); + return str; +} +int main() +{ + INUM a,b; + scanf("%lf %lf %lf %lf",&a.L,&a.R,&b.L,&b.R); + INUM ans; + ans.L=a.L+b.L; + ans.R=a.R+b.R; + printf(format(a)); + printf("+"); + printf(format(b)); + printf("="); + printf(format(ans)); + printf("\n"); + + ans.L=a.L-b.L; + ans.R=a.R-b.R; + printf(format(a)); + printf("-"); + printf(format(b)); + printf("="); + printf(format(ans)); + printf("\n"); + + ans.L=a.L*b.L-a.R*b.R; + ans.R=a.L*b.R+a.R*b.L; + printf(format(a)); + printf("*"); + printf(format(b)); + printf("="); + printf(format(ans)); + printf("\n"); + + ans.L=a.L*b.L+a.R*b.R; + ans.L/=b.L*b.L+b.R*b.R; + ans.R=a.R*b.L-a.L*b.R; + ans.R/=b.L*b.L+b.R*b.R; + printf(format(a)); + printf("/"); + printf(format(b)); + printf("="); + printf(format(ans)); + printf("\n"); + + return 0; +} diff --git a/QUSTOJ/1766.c b/QUSTOJ/1766.c new file mode 100644 index 0000000..375b731 --- /dev/null +++ b/QUSTOJ/1766.c @@ -0,0 +1,15 @@ +#include +#include +char a[256]; +char b[256]; +char c[256]; + +int main() +{ + for(int i=0;i<5;i++) + { + scanf("%s %s %s",a,b,c); + printf("%s %s %s\n",a,b,c); + } + return 0; +} diff --git a/QUSTOJ/1767.c b/QUSTOJ/1767.c new file mode 100644 index 0000000..502aa5e --- /dev/null +++ b/QUSTOJ/1767.c @@ -0,0 +1,36 @@ +#include +#include +#include +typedef struct +{ + char name[1024]; + int id; + int ENG,MATH; +} _sinfo; +_sinfo sinfo[5]; +int cmp(const void* a,const void* b) +{ + int cret; + if((cret=strcmp(((_sinfo*)a)->name,((_sinfo*)b)->name))==0) + { + if(((_sinfo*)a)->ENG==((_sinfo*)b)->ENG) + { + return ((_sinfo*)a)->MATH - ((_sinfo*)b)->MATH; + } + else return ((_sinfo*)a)->ENG - ((_sinfo*)b)->ENG; + } + else return cret; +} +int main() +{ + for(int i=0;i<5;i++) + { + scanf("%d %s %d %d",&sinfo[i].id,sinfo[i].name,&sinfo[i].ENG,&sinfo[i].MATH); + } + qsort(sinfo,5,sizeof(_sinfo),cmp); + for(int i=0;i<5;i++) + { + printf("%d %s %d %d\n",sinfo[i].id,sinfo[i].name,sinfo[i].ENG,sinfo[i].MATH); + } + return 0; +} diff --git a/QUSTOJ/1769.cpp b/QUSTOJ/1769.cpp new file mode 100644 index 0000000..1d53776 --- /dev/null +++ b/QUSTOJ/1769.cpp @@ -0,0 +1,86 @@ +#include +using namespace std; +const int maxnum = 10005; +const int maxEdge= 50005; +const int maxint = 107391822; + +// 边, +typedef struct Edge{ + int u, v; // 起点,重点 + int weight; // 边的权值 +}Edge; + +Edge edge[maxEdge]; // 保存边的值 +int dist[maxnum]; // 结点到源点最小距离 + +int nodenum, edgenum, source; // 结点数,边数,源点 + +// 初始化图 +void init() +{ + // 输入结点数,边数,源点 + cin >> nodenum >> edgenum ; + source=1; + for(int i=1; i<=nodenum; ++i) + dist[i] = maxint; + dist[source] = 0; + for(int i=1; i<=edgenum; i++) + { + cin >> edge[i].u >> edge[i].v >> edge[i].weight; + if(edge[i].u == source) //注意这里设置初始情况 + dist[edge[i].v] = edge[i].weight; + + /* + /// Another + edge[i+1].u=edge[i].v; + edge[i+1].v=edge[i].u; + edge[i+1].weight=-edge[i].weight; + + if(edge[i+1].u == source) //注意这里设置初始情况 + dist[edge[i+1].v] = edge[i+1].weight; + */ + } +} + +// 松弛计算 +void relax(int u, int v, int weight) +{ + if(dist[v] > dist[u] + weight) + dist[v] = dist[u] + weight; +} + +bool Bellman_Ford() +{ + for(int i=1; i<=nodenum-1; ++i) + for(int j=1; j<=edgenum; ++j) + relax(edge[j].u, edge[j].v, edge[j].weight); + bool flag = 1; + // 判断是否有负环路 + for(int i=1; i<=edgenum; ++i) + if(dist[edge[i].v] > dist[edge[i].u] + edge[i].weight) + { + flag = 0; + break; + } + return flag; +} +int main() +{ + //freopen("input3.txt", "r", stdin); + init(); + if(Bellman_Ford()) + //for(int i = 1 ;i <= nodenum; i++) + cout << dist[nodenum] << endl; + else + throw "WTF??"; + return 0; +} +/* +4 6 +1 2 -5 +2 3 -6 +1 3 -9 +2 4 -7 +3 4 -8 +1 4 6 +*/ diff --git a/QUSTOJ/1771.c b/QUSTOJ/1771.c new file mode 100644 index 0000000..0c2e43c --- /dev/null +++ b/QUSTOJ/1771.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int Y,M,D; + scanf("%d %d %d",&Y,&M,&D); + struct tm k; + memset(&k,0,sizeof(k)); + k.tm_year=Y-1900; + k.tm_mon=M-1; + k.tm_mday=D; + k.tm_hour=0; + k.tm_min=0; + k.tm_sec=0; + struct tm s; + memset(&s,0,sizeof(s)); + s.tm_year=1990-1900; + s.tm_mon=1-1; + s.tm_mday=1; + s.tm_hour=0; + s.tm_min=0; + s.tm_sec=0; + time_t a=mktime(&k); + time_t b=mktime(&s); + int day=(a-b)/(3600*24); + if(day%5<3) + { + printf("1\n"); + } + else + { + printf("0\n"); + } + } + return 0; +} diff --git a/QUSTOJ/1772.c b/QUSTOJ/1772.c new file mode 100644 index 0000000..9915080 --- /dev/null +++ b/QUSTOJ/1772.c @@ -0,0 +1,14 @@ +#include +#include +int a[8]; +int cmp(const void* a,const void* b) +{ + return *(int*)b-*(int*)a; +} +int main() +{ + for(int i=0;i<3;i++) scanf("%d",&a[i]); + qsort(a,3,sizeof(int),cmp); + for(int i=0;i<2;i++) printf("%d ",a[i]); + return printf("%d\n",a[2]),0; +} diff --git a/QUSTOJ/1773.c b/QUSTOJ/1773.c new file mode 100644 index 0000000..af51d1b --- /dev/null +++ b/QUSTOJ/1773.c @@ -0,0 +1,15 @@ +#include +#include +#include +char a[1024]; +int main() +{ + gets(a); + int L=strlen(a); + for(int i=L-1;i>=0;i--) + { + printf("%c",a[i]); + } + printf("\n"); + return 0; +} diff --git a/QUSTOJ/1774.c b/QUSTOJ/1774.c new file mode 100644 index 0000000..62ace26 --- /dev/null +++ b/QUSTOJ/1774.c @@ -0,0 +1,15 @@ +#include +#include + +int main() +{ + int tmp; + int odd=0; + int even=0; + while(scanf("%d",&tmp)==1) + { + if(tmp%2==1) odd+=tmp; + else even+=tmp; + } + return printf("%d %d\n",odd,even),0; +} diff --git a/QUSTOJ/1775.c b/QUSTOJ/1775.c new file mode 100644 index 0000000..94bc2fc --- /dev/null +++ b/QUSTOJ/1775.c @@ -0,0 +1,18 @@ +#include +#include + +int main() +{ + int n; + scanf("%d",&n); + double ans=0; + if(n%2==1) + { + for(int k=1;k<=n;k+=2) ans+=1.0/k; + } + else + { + for(int k=2;k<=n;k+=2) ans+=1.0/k; + } + return printf("%f\n",ans),0; +} diff --git a/QUSTOJ/1776.c b/QUSTOJ/1776.c new file mode 100644 index 0000000..dd1a705 --- /dev/null +++ b/QUSTOJ/1776.c @@ -0,0 +1,18 @@ +#include +#include + +char str[128]; +int main() +{ + int t; + scanf("%d",&t); + int sc=0; + int tmp; + while(t--) + { + scanf("%d",&tmp); + if(tmp>sc) scanf("%s",str),sc=tmp; + else scanf("%*s"); + } + return printf("%d %s\n",sc,str),0; +} diff --git a/QUSTOJ/1777.c b/QUSTOJ/1777.c new file mode 100644 index 0000000..0603fa8 --- /dev/null +++ b/QUSTOJ/1777.c @@ -0,0 +1,18 @@ +#include +#include + +int main() +{ + int mi,mj; + int mv=0; + for(int i=1;i<=3;i++) + { + for(int j=1;j<=4;j++) + { + int tmp; + scanf("%d",&tmp); + if(tmp>mv) mi=i,mj=j,mv=tmp; + } + } + return printf("%d\n%d %d\n",mv,mi,mj),0; +}