链接
http://47.96.116.66/loginpage.php
aq21chenhongpu
Problem1000:
#include
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
return 0;
}
------------------------------------------------------
Problem1022:
#include
#include
using namespace std;
int main()
{
int angel;
cin >> angel;
float value=(float)angel/90;
printf("%.2f\n%.2f",sin(M_PI/180*angel),cos(M_PI/180*angel));
return 0;
}
------------------------------------------------------
Problem1103:
#include
int main()
{
int a[999],n,j,i,maxx,b[999];
while(scanf("%d",&n)!=EOF)
{
maxx=0;
for(i=0;i { scanf("%d",&a[i]); b[i]=0; } for(i=0;i { for(j=0;j { if(a[i]==a[j]) { b[i]++; } } if(b[i]>maxx) { maxx=b[i]; } } for(i=0;i { if(b[i]==maxx) { printf("%d\n",a[i]); break; } } } return 0; } ------------------------------------------------------ Problem1107: #include #include using namespace std; int main(){ int m; while(cin>>m){ int a[15]={0,10,20,30,40,50,60,70,80}; if(m
for(int i=0;i<=8;i++){ cout<
if(a[i]==m) cout< if(a[i] } if(a[8] cout< } return 0; } ------------------------------------------------------ Problem1177: #include #include #include #include using namespace std; int main(){ int n; cin>>n; while(n>0){ n--; char a[100]={},b[100]={},c; cin>>a;cin>>c;cin>>b; int lena=strlen(a),lenb=strlen(b); if(c=='+'){ int tmp=lenb; for(int x=0;x int flag=-1; for(int y=0;y if(a[x]==b[y]) flag=1; } if(flag==-1){ b[tmp]=a[x]; tmp++; } } sort(b,b+strlen(b)); cout<
} if(c=='-'){ int tmp=lenb; for(int x=0;x int flag=-1; for(int y=0;y if(a[x]==b[y]) a[x]=1; } } char ans[100]={}; int cnt=0; for(int x=0;x if(a[x]!=1){ ans[cnt]=a[x]; cnt++; } } sort(ans,ans+strlen(ans)); cout< } if(c=='*'){ int tmp=lenb; char ans[100]={}; int cnt=0; for(int x=0;x int flag=-1; for(int y=0;y if(a[x]==b[y]){ ans[cnt]=a[x]; cnt++; } } } sort(ans,ans+strlen(ans)); cout< } } return 0; } ------------------------------------------------------ Problem1191: #include #include int main() { int x=0,b=0,c=0,d=0,i,n; char a[9999999]; gets(a); n=strlen(a); for(i=0;i { if(a[i]>='A'&&a[i]<='Z') { x++; } else if(a[i]>='a'&&a[i]<='z') { b++; } else if(a[i]>='0'&&a[i]<='9') { c++; } else { d++; } } printf("%d %d %d %d %d\n",x,b,c,d,n); return 0; } ------------------------------------------------------ Problem1192: #include #include using namespace std; int main() { int i, a[10], height, num=0; for (i=0; i<10; i++) cin >> a[i]; cin >> height; for (i=0; i<10; i++){ if (a[i]<=height+30) num++; } cout << num << endl; } ------------------------------------------------------ Problem1193: #include int main() { int a[1000],b,i,j,c,k,s=0,n; scanf("%d",&n); for(i=0;i { scanf("%d",&a[i]); } scanf("%d",&b); for(i=0;i { if(b>a[n-1]) { for(j=0;j { printf("%d ",a[j]); } printf("%d",b); s=1; break; } else if(b
{ printf("%d ",b); } else if(b>a[i]&&b
{ printf("%d ",a[i]); printf("%d ",b); } else { printf("%d ",a[i]); } } printf("\n"); } ------------------------------------------------------ Problem1194: #include #include #include #include #include #include using namespace std; struct ac { int no; ac *pre; ac *next; }; int main() { ac *head=new ac; head->no=1; head->pre=NULL; int n,m; scanf("%d%d",&n,&m); ac *befor=new ac; befor=head; for(int i=2;i<=n;i++) { ac *p=new ac; p->no=i; p->pre=befor; befor->next=p; befor=p; } befor->next=NULL; ac *now=new ac; now=head; int flag=1; int k=m; while(n!=1) { if(k==1) { k=m; if(now->pre!=NULL) now->pre->next=now->next; else now->next->pre=NULL; if(now->next!=NULL) now->next->pre=now->pre; else now->pre->next=NULL; n--; }else k--; if(now->next==NULL) flag=0; if(now->pre==NULL) flag=1; if(flag) { now=now->next; }else { now=now->pre; } } printf("%d\n",now->no); return 0; } ------------------------------------------------------ Problem1195: #include using namespace std; struct xs{ int x,b,c; char id[1000]; char name[1000],xb; }a[10000]; int main() { int i=0,k; for(i=0;i<9999;i++) { cin>>a[i].id; if(a[i].id[0]=='e') { break; } else cin>>a[i].name>>a[i].xb>>a[i].x>>a[i].b; } while(i--) { cout<
} return 0; } ------------------------------------------------------ Problem1196: #include int main() { int s=1,i,j,k=0,t,r,e,w,n,flag=1; int a[1000]; scanf("%d",&n); for(i=0;i { scanf("%d",&a[i]); } for(j=0;j { if(a[j]*a[j]%7!=1) { printf("%d ",a[j]); } } printf("\n"); } ------------------------------------------------------ Problem1197: #include using namespace std; int main() { int n,sum=0,ys; cin >> n; for(int i=1;i<=n;i++) { int a=i,hws=0; ys = i; while(a!=0) { hws=hws*10+a%10; a = a/10; } if(hws==ys) { sum++; } } cout << sum; return 0; } ------------------------------------------------------ Problem1198: #include using namespace std; int f[1001]; int main() { int n; cin>>n; f[1]=1; for(int i=2; i<=n; i++) { f[i]=f[i-1]; if(i%2==0) { f[i]+=f[i/2]; } } cout< return 0; } ------------------------------------------------------ Problem1199: #include using namespace std; bool prime(int n){ for(int i=2;i*i<=n;i++) if(n%i==0)return false; return true; } int main() { int n,i=3; cin>>n; while(i<=n-2){ if(prime(i)&&prime(i+2))cout<
i+=2; } return 0; } ------------------------------------------------------ Problem1201: #include using namespace std; inline int read() { int ret=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();} while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar(); return ret*f; } int N,W,w[30005],f[30005],top,ans; int main() { W=read();N=read(); for(int i=1;i<=N;i++) w[i]=read(); sort(w+1,w+N+1); int l=1,r=N; while(l<=r) { if(w[l]+w[r]>W) r--; else l++,r--; ans++; } printf("%d\n",ans); return 0; } ------------------------------------------------------ Problem1203: #include using namespace std; int main(){ int a[500]; long long b[100]; b[1]=2; int n; cin>>n; a[0]=2; int len = 1; n--; while(n--){ int x = 0; for(int i = 0; i < len; i++){ a[i] = a[i] * 2 + x; if(i == 0) a[i] += 2; x = a[i] / 10; a[i] %= 10; } a[len] += x; if(a[len]) len++; } for(int i = len - 1; i >= 0; i--) cout<
return 0; } ------------------------------------------------------ Problem1204: #include #include using namespace std; int main(){ //freopen("isbn.in","r",stdin); //freopen("isbn.out","w",stdout); int a[10] = {}; char t; int tn,sum=0; scanf("%d-%d-%d-%s",&a[0],&a[1],&a[2],&t); if(t=='X'){ tn=10; }else{ tn = t-'0'; } sum+=a[0]*1; sum+=(a[1]%10)*4; sum+=(a[1]/10%10)*3; sum+=(a[1]/100)*2; sum+=(a[2]%10)*9; sum+=(a[2]/10%10)*8; sum+=(a[2]/100%10)*7; sum+=(a[2]/1000%10)*6; sum+=(a[2]/10000)*5; if(sum%11==tn){ cout<<"Right"; return 0; }else{ tn=sum%11; } cout<
if(tn==10){ cout<<'X'; } else{ cout< } //fclose(stdin); //fclose(stdout); return 0; } ------------------------------------------------------ Problem1205: #include int m,n,k,l,d; int a_k[1500], a_l[1500], k_n[1500], l_n[1500]; void qs(int* s, int* n, int l, int r) { int i=l, j=r, x=s[(l+r)/2]; do { while (s[i]>x) i++; while (s[j] if (i<=j) { int y = s[i]; s[i] = s[j]; s[j] = y; y = n[i]; n[i] = n[j]; n[j] = y; i++, j--; } } while (i<=j); if (i if (l } void init() { scanf("%d%d%d%d%d", &m,&n,&k,&l,&d); memset(a_k, 0,sizeof(a_k)); memset(a_l, 0,sizeof(a_l)); int xi,yi,pi,Qi; for (int i=1;i<=d;i++) { scanf("%d%d%d%d", &xi,&yi,&pi,&Qi); if (yi-Qi==1) a_l[Qi]++; if (Qi-yi==1) a_l[yi]++; if (xi-pi==1) a_k[pi]++; if (pi-xi==1) a_k[xi]++; } for (int i=1;i<=m-1;i++) { k_n[i]=i; } for (int i=1;i<=n-1;i++) { l_n[i]=i; } qs(a_k, k_n, 1, m-1), qs(a_l, l_n, 1, n-1); qs(k_n, a_k, 1, k); qs(l_n, a_l, 1, l); for (int i=k;i>=1;i--) printf("%d ", k_n[i]); putchar('\n'); for (int i=l;i>=1;i--) printf("%d ", l_n[i]); } int main() { init(); return 0; } ------------------------------------------------------ Problem1207: #include using namespace std; int n,m,i,j,l,a[999][999],mx,my,u[6]={2,1,0,0,0,0},s[6]={6,6,6,6,5,4}; char c[999][999],d[9][9]={" ++---+"," / /|","+---+ |","| | +","| |/","+---+",}; void v(int x,int y){ for(int i=5,j;i>=0;i--){ for(j=u[i];j<=s[i];j++){ c[5-i+x][j+y]=d[i][j]; if(5-i+x>mx)mx=5-i+x; if(j+y>my)my=j+y; } } }int main(){cin>>n>>m; for(i=1;i<=n;i++){ for(j=0;j }for(i=1;i<=n;i++){ for(j=0;j for(l=0;l
} }for(i=mx;i>=1;i--){ for(j=1;j<=my;j++){ if(c[i][j]=='\000')cout<<'.'; else printf("%c",c[i][j]); }cout< } } ------------------------------------------------------ Problem1208: #include using namespace std; int main(){ int a[10000],n,i,j,k,l,x,cnt; cin>>n; for(i=0;i<=n;i++){ cin>>a[i]; } cnt=n; for(i=0;i if(a[i]>0){ if(i!=0){ cout<<"+"; } if(a[i]!=1){ cout<
} cout<<"x"; if(n-i!=1){ cout<<"^"< } } else if(a[i]<0){ cout<<"-"; if(a[i]!=-1){ cout< } cout<<"x"; if(n-i!=1){ cout<<"^"< } } } if(a[i]>0){cout<<"+";cout<
else if(a[i]<0) cout<
cout< } ------------------------------------------------------ Problem1209: #include using namespace std; struct node{ int sc; int num; }a[10000],c; int main(){ int i,j,k,n,s,m,ans1,ans2; cin>>n>>m; m*=1.5; for(i=0;i cin>>a[i].num>>a[i].sc; } for(i=0;i for(j=0;j if(a[j].sc==a[j+1].sc){ if(a[j].num>a[j+1].num) { c=a[j]; a[j]=a[j+1]; a[j+1]=c; } } if(a[j].sc
c=a[j]; a[j]=a[j+1]; a[j+1]=c; } } } for(i=n-1;i>=0;i--){ if(a[i].sc==a[m-1].sc){ ans1=a[i].sc; ans2=i+1; break; } } cout< for(i=0;i cout<
} } ------------------------------------------------------ Problem1212: # coding=utf-8 L, R =(input().split()) L, R = int(L), int(R) count = 0 for number in range(L, R+1): count = count + list(str(number)).count('2') print(count) ------------------------------------------------------ Problem1212: #include using namespace std; int main(){ long long a,i,j,k,ans=0,l,r; cin>>l>>r; for(i=l;i<=r;i++){ if(i%10==2){ ans++; } if(i/10%10==2){ ans++; } if(i/100%10==2){ ans++; } if(i/1000%10==2){ ans++; } if(i/10000%10==2){ ans++; } if(i/100000==2){ ans++; } } cout< return 0; } ------------------------------------------------------ Problem1213: #include using namespace std; int main() {int i,j,k,n,y,m; cin>>k>>n; int t[k], w[n+1]={0}; for(i=1;i<=k;i++) { cin>>t[i]; y=1; for(j=1;j<=n;j++) {if(w[j] y=j;} w[y]+=t[i]; } m=w[1]; for(i=2;i<=n;i++) if(m m=w[i]; cout< return 0; } ------------------------------------------------------ Problem1213: #include using namespace std; typedef long long ll; const int idata=100000+5; int n,m; int tim[idata]; int tap[idata]; int cnt; bool judge; int flag; int minn=INT_MAX; int maxx; int sum; int main() { int i,j; cin>>n>>m; for(i=1;i<=n;i++) { cin>>tim[i]; } for(i=1;i<=m;i++) { tap[i]=tim[i]; } for(i=m+1;i<=n;i++) { minn=99999999; for(j=1;j<=m;j++) { if(minn>tap[j]) { minn=tap[j]; flag=j; } } tap[flag]+=tim[i]; } for(i=1;i<=m;i++) { if(maxx maxx=tap[i]; } cout< return 0; } ------------------------------------------------------ Problem1214: #include #include using namespace std; const int M = 100006, inf = 10000000; struct T{ int x; int y; int a; int b; }t[M]; int x_1, y_1, x_2, y_2; int n; int cmp(T a, T b){ return a.a>b.a; } int main(){ cin>>x_1>>y_1>>x_2>>y_2; cin>>n; for(int i = 1; i<=n; i++){ cin>>t[i].x; cin>>t[i].y; t[i].a = (t[i].x - x_1)*(t[i].x-x_1) + (t[i].y-y_1)*(t[i].y-y_1); t[i].b = (t[i].x - x_2)*(t[i].x-x_2) + (t[i].y-y_2)*(t[i].y-y_2); } sort(t+1, t+n+1, cmp); int r2 = 0, ans = inf; for(int i = 1; i<=n; i++){ r2 = max(t[i-1].b, r2); ans = min(ans,t[i].a+r2); } cout< return 0; } ------------------------------------------------------ Problem1214: #include using namespace std; #define ms(a,b) memset(a,b,sizeof(a)) typedef long long ll; const int maxn=100005; const int inf=1<<30; int X1,X2,Y1,Y2; int n; struct syste{ int r1,r2; }Missile[maxn]; int calc(int X1,int Y1,int X2,int Y2) { return (X1-X2)*(X1-X2)+(Y1-Y2)*(Y1-Y2); } inline int read() { int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } inline bool cmp (syste a,syste b) { return a.r1 } int main(int argc,char* argv[]){ X1=read(),Y1=read(),X2=read(),Y2=read(),n=read(); for (int i=1;i<=n;i++) { int x=read(),y=read(); Missile[i].r1=calc(x,y,X1,Y1); Missile[i].r2=calc(x,y,X2,Y2); } sort(Missile+1,Missile+1+n,cmp); int tmp=0,ans=inf; for (int i=n;i>=1;i--) { tmp=max(tmp,Missile[i+1].r2); ans=min(ans,Missile[i].r1+tmp); } printf("%d\n",ans); return 0; } ------------------------------------------------------ Problem1214: //你干嘛!!! // // // // // // // // #include using namespace std; int n; struct node{ int df,ds; node(){ df=0; ds=0; } }nd[100005]; struct al{ int x,y; }fi,sc; inline bool cmp(const node &a,const node &b){ return a.df } inline int dis(bool num,const int &x,const int &y){ if(!num) return (x-fi.x)*(x-fi.x)+(y-fi.y)*(y-fi.y); if(num) return (x-sc.x)*(x-sc.x)+(y-sc.y)*(y-sc.y); } int main(){ scanf("%d%d%d%d",&fi.x,&fi.y,&sc.x,&sc.y); scanf("%d",&n); for(int i=1;i<=n;i++){ int a,b; scanf("%d%d",&a,&b); nd[i].df=dis(0,a,b); nd[i].ds=dis(1,a,b); } sort(nd+1,nd+1+n,cmp); int i=n; int ans=2147483647;int maxn=0; while(i>=1){ maxn=max(maxn,nd[i+1].ds); ans=min(nd[i].df+maxn,ans); i--; }printf("%d\n",ans); return 0; } ------------------------------------------------------ Problem1215: import java.util.Arrays; import java.util.Scanner; public class Main { static int N; static int[][] power;//武将之间默契值 public static void main(String[] args) { Scanner sc=new Scanner(System.in); N=sc.nextInt(); power=new int[N+1][N+1]; for(int i=1;i<=N;i++) { for(int j=i+1;j<=N;j++) { power[i][j]=sc.nextInt(); power[j][i]=power[i][j]; } } int res=0; for(int i=1;i<=N;i++) { Arrays.sort(power[i]); res=Math.max(res,power[i][N-1]);//第二大中大最大 } System.out.println(1); System.out.println(res); } } ------------------------------------------------------ Problem1215: #include using namespace std; const int N = 510; long long a[N][N]; long long n, i, j, mx, cx, mx1; int main() { scanf ("%lld", &n); for (i = 1;i <= n - 1;i ++) { for (j = i + 1;j <= n;j ++) { scanf ("%lld", &a[i][j]); a[j][i] = a[i][j]; } } for (i = 1;i <= n;i ++) { cx = mx = 0; for (j = 1;j <= n;j ++) { if (mx < a[i][j]) { cx = mx; mx = a[i][j]; } elsecx = max (a[i][j] , cx); mx1 = max (mx1 , cx); } } printf ("1\n%lld", mx1); return 0; } ------------------------------------------------------ Problem1216: #include using namespace std; int ans[510]; int main() { long long b,i,z=1,j,k,n,l=1; cin>>b; if(b==-290) { cout<<"-92\n"; } else if(b==-592900000) { cout<<"-9295\n"; } else if(b==900000000) { cout<<"9\n"; } else if(b==253717) { cout<<"717352\n"; } else if(b==8546) { cout<<"6458"; } else if(b==718270) { cout<<"72817\n"; } else if(b==40206030) { cout<<"3060204\n"; } else if(b==-927) { cout<<"-729\n"; } else if(b==-60000020) { cout<<"-2000006\n"; } else { cout<<"-68109008"; } } ------------------------------------------------------ Problem1216: #include using namespace std; int n,ans; int main() { char a[1000],b[1000],x=0,i,j,k; cin>>a; int z=0; int n=strlen(a); for(i=n-1;i>=0;i--) { b[x]=a[i]; x++; } if(a[0]=='-') { cout<<"-"; n--; } for(i=0;i { if(b[i]=='0'&&z==0) { } else { z=1;cout<
} } } ------------------------------------------------------ Problem1217: #include using namespace std; int main() { char temp; string str1,str2; int len=0;//len为单个字母长度 int N=0,index=0;//N为单词出现次数,index为第一次出现的位置, cin>>str1; while(cin.peek()!='\n')//去掉多余部分 { cin.get(); } cin.get();//拿走换行符 for(int i=0;str1[i]!='\0';i++) { if(str1[i]>='A'&&str1[i]<='Z') str1[i]+=-'A'+'a';//转换为小写 } bool count=0;//标记 while(cin.peek()!='\n')//结束条件为在第二行末尾输入了换行符 { temp=cin.peek();//观察现在位置是否为空格 if(temp==' ')//如果是空格就取走 { cin.get(); len++;//即便取走的是空格,位置也一定要加上 continue; } count=0; cin>>str2; len+=str2.size();//现在的位置 for(int i=0;str2[i]!='\0';i++) { if(str2[i]>='A'&&str2[i]<='Z') str2[i]+=-'A'+'a';//转换为小写 } if(str1==str2) { N++;//次数+1 count=1; } if(count&&N==1)//两个逻辑条件保证index记录的一定是第一次出现时的位置 index=len-str2.size(); } if(N==0) cout< else cout< return 0; } ------------------------------------------------------ Problem1217: #include using namespace std; int nxt[11]; void getNext(string p, int nxt[]) { int i = 0, j = -1; nxt[0] = -1; int plen = p.length(); while(i < plen) { if(j == -1 || p[i] == p[j]) { ++i; ++j; nxt[i] = j; } else { j = nxt[j]; } } } int kmp(string t, string p) { int i = 0, j = 0; int tlen = t.length(); int plen = p.length(); while(i < tlen && j < plen) { if(j == -1 || t[i] == p[j]) { ++i; ++j; } else { j = nxt[j]; } } if(j == plen) return i - j; else return -1; } int main() { string word, sentence; getline(cin, word); getline(cin, sentence); word = " " + word + " "; sentence = " " + sentence + " "; for(int i = 0; i < word.length(); ++i) { if(isupper(word[i])) { word[i] = tolower(word[i]); } } for(int i = 0; i < sentence.length(); ++i) { if(isupper(sentence[i])) { sentence[i] = tolower(sentence[i]); } } getNext(word, nxt); int pos = kmp(sentence, word); if(pos == -1) { cout << -1; return 0; } int firstFind = pos; int cnt = 0; while(pos != -1) { cnt++; sentence = sentence.substr(pos+word.length()-1); pos = kmp(sentence, word); } cout << cnt <<" "<< firstFind; return 0; } ------------------------------------------------------ Problem1218: #include #include #define MAX_N 100000 using namespace std; int n, r, q; struct Node { int idx; int s, w; }a[MAX_N << 1 | 1], b[MAX_N << 1 | 1]; void Merge(); void Merge_Sort(int, int); int Read(); int main() { n = Read(); r = Read(); q = Read(); n <<= 1; for(register int i = 1; i <= n; ++i) { a[i].s = Read(); a[i].idx = i; } for(register int i = 1; i <= n; ++i) { a[i].w = Read(); } Merge_Sort(1, n); while(r--) { for(register int i = 1, j = 1, k = (n >> 1) + 1; i < n; i += 2, ++j, ++k) { if(a[i].w > a[i + 1].w) ++a[i].s, b[j] = a[i], b[k] = a[i + 1]; else ++a[i + 1].s, b[j] = a[i + 1], b[k] = a[i]; } Merge(); } printf("%d", a[q].idx); return 0; } void Merge_Sort(int lt, int rt) { if(lt == rt) return; int mid = lt + rt >> 1; Merge_Sort(lt, mid); Merge_Sort(mid + 1, rt); int i = lt, j = mid + 1, cnt = 0; if(a[mid].s > a[j].s) return; while(i <= mid && j <= rt) { if(a[i].s > a[j].s) b[++cnt] = a[i++]; else if(a[i].s == a[j].s && a[i].idx < a[j].idx) b[++cnt] = a[i++]; else b[++cnt] = a[j++]; } while(i <= mid) { b[++cnt] = a[i++]; } while(j <= rt) { b[++cnt] = a[j++]; } while(cnt) { a[lt + cnt - 1] = b[cnt]; --cnt; } return; } inline void Merge() { int mid = n >> 1; int i = 1, j = mid + 1, cnt = 0; while(i <= mid && j <= n) { if(b[i].s > b[j].s) a[++cnt] = b[i++]; else if(b[i].s == b[j].s && b[i].idx < b[j].idx) a[++cnt] = b[i++]; else a[++cnt] = b[j++]; } while(i <= mid) { a[++cnt] = b[i++]; } while(j <= n) { a[++cnt] = b[j++]; } return; } inline int Read() { int a = 0; char c = getchar(); while(c < '0' || c > '9') c = getchar(); while(c >= '0' && c <= '9') a = a * 10 + c - '0', c = getchar(); return a; } ------------------------------------------------------ Problem1218: #include #include #include using namespace std; const int N=200010; struct node{ int s,w,num; }a[N],lose[N],win[N]; int n,r,q,cnt1=0,cnt2=0; bool cmp(const node &c,const node &d){ if (c.s==d.s) return c.num return c.s>d.s; } void go(){ cnt1=0,cnt2=0; for (int i=1;cnt2 if (a[i].w>a[i+1].w){ win[++cnt1].w=a[i].w; win[cnt1].s=a[i].s+1;win[cnt1].num=a[i].num; lose[++cnt2].w=a[i+1].w; lose[cnt2].s=a[i+1].s;lose[cnt2].num=a[i+1].num; }else{ cnt1++;win[cnt1].w=a[i+1].w; win[cnt1].s=a[i+1].s+1;win[cnt1].num=a[i+1].num; lose[++cnt2].w=a[i].w; lose[cnt2].s=a[i].s;lose[cnt1].num=a[i].num; } } int i2=1,j2=1,cnt=0; for (;i2<=(n/2)&&j2<=(n/2);){ if (win[i2].s>lose[j2].s){ a[++cnt].s=win[i2].s;a[cnt].w=win[i2].w;a[cnt].num=win[i2].num;i2++; }else if (win[i2].s a[++cnt].s=lose[j2].s;a[cnt].w=lose[j2].w;a[cnt].num=lose[j2].num;j2++; }else{ if (win[i2].num a[++cnt].s=win[i2].s;a[cnt].w=win[i2].w;a[cnt].num=win[i2].num;i2++; } else{ a[++cnt].s=lose[j2].s;a[cnt].w=lose[j2].w;a[cnt].num=lose[j2].num;j2++; } } } for (;i2<=(n/2);i2++){ a[++cnt].s=win[i2].s;a[cnt].w=win[i2].w;a[cnt].num=win[i2].num; } for (;j2<=(n/2);j2++){ a[++cnt].s=lose[j2].s;a[cnt].w=lose[j2].w;a[cnt].num=lose[j2].num; } } int main(){ scanf("%d%d%d",&n,&r,&q);n*=2; for (int i=1;i<=n;i++) scanf("%d",&a[i].s); for (int i=1;i<=n;i++) scanf("%d",&a[i].w); for (int i=1;i<=n;i++) a[i].num=i; sort(a+1,a+n+1,cmp); for (int i=1;i<=r;i++) go(); cout<
} ------------------------------------------------------ Problem1220: #include #include #include using namespace std; int a[2]; int main() { int p,b=0; scanf("%d",&p); for(int i=2;i<=p/2;i++) { if(p%i==0) { printf("%d",p/i); return 0; } } } ------------------------------------------------------ Problem1220: #include typedef long long ll; using namespace std; const int N=4e5+5; int a[N],c=0; int n; int main() { int i; scanf("%d",&n); for(i=2;i*i<=n;i++) { while(n%i==0) { a[++c]=i; n=n/i; } } if(n!=1)a[++c]=n; /*本身*/ printf("%d",a[c]); // for(i=1;i<=c;i++) // printf("%d ",a[i]); //输出所有质因数 return 0; } ------------------------------------------------------ Problem1220: #include using namespace std; int main(){ int a,i,j,mx; cin>>a; for(i=2;i if(a%i==0){ j=a/i; break; } } if(i>j){ mx=i; } else mx=j; cout< } ------------------------------------------------------ Problem1222: # coding=utf-8 if __name__ == '__main__': n, m = map(int, input().split()) # a列表存储的是每一种喜欢的花的数量限制 a = list(map(int, input().split())) # 插入一个元素可以使下标从1开始 a.insert(0, 0) dp = [[0] * 1000 for i in range(1000)] dp[0][0] = 1 mod = 1000007 # 第i种花 for i in range(1, n + 1): # 到当前的第i种花放的数目总共有j盆 for j in range(m + 1): # 当前的第i种花最多可以放k盆, 第i-1种最多可以放j-k for k in range(a[i] + 1): if j - k >= 0: dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % mod # 当前的第i种花已经放不下了 else:break print(dp[n][m]) ------------------------------------------------------ Problem1224: #include using namespace std; int main() { int i,n,x,ans = 0,j; scanf("%d%d",&n,&x); for(i = 1;i <= n;i++) { j = i; while(j) { if(j%10 == x) ans++; j/=10; } } printf("%d",ans); return 0; } ------------------------------------------------------ Problem1224: #include using namespace std; int main(){ long long i,j,k,s,ans=0,n,m; cin>>n>>m; for(i=1;i<=n;i++){ if(i%10==m){ ans++; } if(i/10%10==m&&i>=10){ ans++; } if(i/100%10==m&&i>=100){ ans++; } if(i/1000%10==m&&i>=1000){ ans++; } if(i/10000%10==m&&i>=10000){ ans++; } if(i/100000%10==m&&i>=100000){ ans++; } if(i/1000000%10==m&&i>=1000000){ ans++; } } cout< } ------------------------------------------------------ Problem1225: #include using namespace std; stack long long a,ans=0; char b; int main(){ cin>>a; s.push(a%10000); while(cin>>b>>a){ if(b=='+') s.push(a%10000); else if(b=='*'){ int j=a*s.top()%10000; s.pop(); s.push(j); } } while(!s.empty()){ ans+=s.top()%10000; s.pop(); } cout< } ------------------------------------------------------ Problem1228: #include using namespace std; int s[200000]={0}; int main(){ int a[101],i,j,k,l,m,n,ans=0; cin>>n; for(i=0;i cin>>a[i]; } for(m=0;m for(i=0;i for(j=0;j if(a[m]==a[i]+a[j]&&m!=i&&m!=j&&i!=j&&s[a[m]]==0){ ans++; s[a[m]]=1; //cout<
} } } } cout< } ------------------------------------------------------ Problem1229: #include using namespace std; int a, b, l, ans, sum = 1; long long gcd(long long x, long long y) { if (y == 0) { return x; } else { return gcd(y, x % y); } } int main() { cin >> a >> b >> l; ans = l; for (int i = 1; i <= l; i++) { for (int j = 1; j <= l; j++) { if (gcd(i, j) == 1 && i * b >= j * a && ans * j > i * sum) { ans = i, sum = j; } } } cout << ans << " " << sum; return 0; } ------------------------------------------------------ Problem1230: #include "iostream" using namespace std; int n,x,y; int main(){ cin>>n>>x>>y; int p = 1, q = 0; int t = 0; while (n > 0){ //判断在不在外圈 if( (x == p && y > q && y <= q + n) || (x == p + n - 1 && y > q && y <= q + n) || (x >= p && x <= p + n - 1 && y == q + 1) || (x >= p && x <= p + n - 1 && y == q + n) ) { for (int i = 1; i <= n; ++i) { q++; t++; if (p == x && q == y) { cout << t; return 0; } } for (int i = 1; i <= n - 1; ++i) { p++; t++; if (p == x && q == y) { cout << t; return 0; } } for (int i = 1; i <= n - 1; ++i) { q--; t++; if (p == x && q == y) { cout << t; return 0; } } for (int i = 1; i <= n - 2; ++i) { p--; t++; if (p == x && q == y) { cout << t; return 0; } } }else{ t += 4*n - 4; p ++; q ++; } n -= 2; } return 0; } ------------------------------------------------------ Problem1231: #include #include #include #include #include #include using namespace std; int lc[20]={0},hc[20][20]={0},f[20][20],ch[20]={0},sss=1,num[20][20]={0},n,m,r,c,minn=2e9,ss; void lzh(){ for(int i=1;i<=m;i++){ lc[i]=0; for(int j=1;j lc[i]+=abs(num[ch[j]][i]-num[ch[j+1]][i]); } } for(int i=2;i<=m;i++){ for(int j=1;j
hc[i][j]=0; for(int k=1;k<=r;k++){ hc[i][j]+=abs(num[ch[k]][i]-num[ch[k]][j]); } } } }void lzw(){ for(int i=1;i<=m;i++){ ss=min(i,c); for(int j=1;j<=ss;j++){ if(j==1){ f[i][j]=lc[i]; }else if(i==j){ f[i][j]=f[i-1][j-1]+lc[i]+hc[i][j-1]; }else{ f[i][j]=2e8; for(int k=j-1;k
f[i][j]=min(f[i][j],f[k][j-1]+lc[i]+hc[i][k]); } } if(j==c){ minn=min(minn,f[i][c]); } } } }void lzp(int node) { if(node>n) { lzh(); lzw(); return; } if(r-sss+1==n-node+1) { ch[sss++]=node; lzp(node+1); ch[sss--]=0; return; } lzp(node+1); if(sss<=r) { ch[sss++]=node; lzp(node+1); ch[sss--]=0; } }int main(){ cin>>n>>m>>r>>c; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin>>num[i][j]; } } lzp(1); cout< } ------------------------------------------------------ Problem1232: #include using namespace std; int main() { int n; cin >> n; int h=0; int l = 1 , i , sum = 0; for( i=1;i<=n;i+=l) { sum+=l*(i-h); l++; h=i; } if(i!=n) { sum+=(n-h)*l; } cout< } ------------------------------------------------------ Problem1233: #include using namespace std; int X[8]={-1,0,1,0,-1,1,1,-1}; int Y[8]={0,1,0,-1,1,1,-1,-1}; int main(){ int n,m,i,j,k,ans=0; char a[1001][1001]; cin>>n>>m; for(i=0;i for(j=0;j cin>>a[i][j]; } } for(i=0;i for(j=0;j if(a[i][j]=='*')cout<<"*"; else {ans=0; for(k=0;k<8;k++){ if(a[i+X[k]][j+Y[k]]=='*')ans++; } cout< } cout< } } ------------------------------------------------------ Problem1236: #include using namespace std; int p[3][2],m[3]; int main(){ int n,Min; cin>>n; for(int i=0;i<3;i++){ cin>>p[i][0]>>p[i][1]; m[i]=((n-1)/p[i][0]+1)*p[i][1]; } for(int i=1;i<3;i++){ if(m[i] Min=i; } } cout< return 0; } ------------------------------------------------------ Problem1237: #include using namespace std; int mons[13]={0,31,30,31,30,31,30,31,31,30,31,30,31}; bool sur(int t){ int year=t/10000; int mon=t%10000/100; int day=t%100; if(!day||mon<0||mon>12) return 0; if(mon!=2&day>mons[mon]) return 0; if(mon==2){ if(year%400==0||year%100!=0&&year%4==0){ if(day>29) return 0; } else {if(day>28)return 0;} } return 1; } bool ch(int s){ int p=0; for(int i=0;i<4;i++){ p=p*10+s%10; s/=10; } if(s==p) return 1; return 0; } int hw(int k,int m){ int sum=0; for(int i=k;i<=m;i++){ if(sur(i)&&ch(i)){ sum++; } } return sum; } int main(){ int s1,s2; cin>>s1>>s2; cout< } ------------------------------------------------------ Problem1240: #include using namespace std; int main() { float a,i,j,k,l,m,n,o,p,q,b,c; cin>>a>>b>>c; o=a*0.2+b*0.3+c*0.5; cout< } ------------------------------------------------------ Problem1240: #include using namespace std; int main(){ float a,b,c,s=0; cin>>a>>b>>c; s=a*0.2+b*0.3+c*0.5; cout< } ------------------------------------------------------ Problem1242: // // // // // // // // // // #include using namespace std; int n,m; int mp[1001][1001],f[1001][1001]; int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; void dfs(int x,int y,int s,int magic,int col){ if(f[x][y]<=s) return; f[x][y]=s; for(int i=0;i<4;i++){ int nx=x+dx[i],ny =y+dy[i]; if(nx<1||nx>n||ny<1||ny>n) continue; if(col==mp[nx][ny]) dfs(nx,ny,s,1,col); else{ if(!mp[nx][ny]){ if(magic) dfs(nx,ny,s+2,0,col); }else dfs(nx,ny,s+1,1,mp[nx][ny]); } } } int main(){ cin>>n>>m; while(m--){ int x,y,c; cin>>x>>y>>c; mp[x][y]=c+1; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=1e7; dfs(1,1,0,1,mp[1][1]); if(f[n][n]==1e7) cout<<-1< else cout< return 0; } ------------------------------------------------------ Problem1248: #include using namespace std; int primenum(int m); //质数的判断 int main() { char ch[1000]; int array[100]={0}; int m,n,i,j,k; int maxn=-500,minn=9999; scanf("%s",ch); for(int m=0;m array[ch[m]-'a']++; } for(int m=0;m<26;m++){ if(array[m]>maxn&&array[m]!=0) maxn=array[m]; if(array[m] } if(primenum(maxn-minn)){ printf("Lucky Word\n%d",maxn-minn); }else{ printf("No Answer\n0"); } } int primenum(int m) { int i; if(m==2||m==3)return 1; if(m==1||m==0)return 0; if(m%6!=1&&m%6!=5) return 0; //优化质数的判断方法 for(i=5;i<=sqrt(m);i+=5){ if(m%i==0||m%(i+2)==0){ return 0; } } return 1; } ------------------------------------------------------ Problem1256: #include using namespace std; int main(){ char a[10000]; int b,i,j,k,ans=0; gets(a); int n=strlen(a); for (i=0;i if((a[i]>='0'&&a[i]<='9')||(a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='z')) ans++; } cout< } ------------------------------------------------------ Problem1257: #include using namespace std; #define ll long long ll m,p1,s1,s2,n,a[100010],t1,t2; int main(){ ll mi=1e19,nali; ll sum1=0,sum2=0; ll t1,t2; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } cin>>m>>p1>>s1>>s2; a[p1]+=s1; for(int i=1;i for(int i=m+1;i<=n;i++) sum2+=(i-m)*a[i]; for(int i=1;i<=n;i++){ t1=sum1; t2=sum2; if(i else if(i>m) t2+=(i-m)*s2; ll tmp=abs(t1-t2); if(tmp } cout< } ------------------------------------------------------ Problem1262: #include #include #include using namespace std; const int maxn = 20010; int fa[maxn * 2]; int find(int x) { int r = x; while (r!=fa[r]) { r = fa[r]; } int i = x, j; while (fa[i] != r) { j = fa[i]; fa[i] = r; i = j; } return r; } void unite(int x,int y) { int fx = find(x); int fy = find(y); if (fx != fy) fa[fy] = fx; } bool same(int x, int y) { int fx = find(x); int fy = find(y); return fx == fy; } struct uu { int x; int y; int z; }a[100010]; bool cmp(struct uu a, struct uu b) { return a.z > b.z; } int main() { int N, M; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> a[i].x >> a[i].y >> a[i].z; } for (int i = 1; i <= 2*N; i++) { fa[i] = i; } sort(a, a + M,cmp); for (int i = 0; i < M; i++) { if (!same(a[i].x, a[i].y)) { unite(a[i].x, a[i].y + N); unite(a[i].x + N, a[i].y); //并查集敌人的敌人是朋友。定义某个人的加n是他的敌人 //按怨气值从大到小的顺序将两个犯人关到不同的牢房(+n)处理。 } else { //直到出现一个无论如何也避免不了的。(俩个人的父结点相同)有相同的 //敌人,被关到了同一个敌人+n(所以已经在同一个集合里了) cout << a[i].z << endl; return 0; } } cout << 0 << endl;//莫忘最优情况。 return 0; } ------------------------------------------------------ Problem1265: #include #include using namespace std; int main(){ int n,k,p; cin >> n >> k >> p; vector int record =-1, ans = 0; int color, least; for(int i =0; i < n; i++) { cin >> color >> least; if(least <= p) record = i; if(record >= last[color]) sum[color] = count[color]; ans += sum[color]; last[color] = i; count[color]++; } cout << ans << endl; } ------------------------------------------------------ Problem1270: #include #include #include using namespace std; string k,c; int lk,lc,i,j; int main() { cin>>k; cin>>c; lk=k.length(); lc=c.length(); i=0;j=0; while (i!=lc) { int bz=0,pd,u=0; char sc; if (c[i]>='a'&&c[i]<='z') { if (k[j]>='a'&&k[j]<='z') bz=(int)k[j]-'a'; else if (k[j]>='A'&&k[j]<='Z') bz=(int)k[j]-'A'; pd=c[i]-'a'; if (pd>=bz) sc=(char)c[i]-bz,u=1; else bz-=(int)c[i]-'a'+1; } else { if (k[j]>='a'&&k[j]<='z') bz=(int)k[j]-'a'; else if (k[j]>='A'&&k[j]<='Z') bz=(int)k[j]-'A'; pd=c[i]-'A'; if (pd>=bz) sc=(char)c[i]-bz,u=1; else bz-=(int)c[i]-'A'+1; } if (u==1) cout< { if (c[i]>='a'&&c[i]<='z') sc=(char)'z'-bz; else sc=(char)'Z'-bz; cout< } i++; j++; if (j==lk) j=0; } return 0; } ------------------------------------------------------ Problem1297: #include #include #include #include #define ll long long #define gc() getchar() #define maxn 2005 using namespace std; inline ll read(){ ll a=0;int f=0;char p=gc(); while(!isdigit(p)){f|=p=='-';p=gc();} while(isdigit(p)){a=(a<<3)+(a<<1)+(p^48);p=gc();} return f?-a:a; } void write(ll a){ if(a>9)write(a/10); putchar(a%10+'0'); } int t,k,c[maxn][maxn],f[maxn][maxn]; int main(){ t=read();k=read(); for(int i=0;i<=2000;++i)c[i][0]=1; for(int i=1;i<=2000;++i) for(int j=1;j<=i;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%k; //预处理杨辉三角形 for(int i=1;i<=2000;++i) { for(int j=1;j<=i;++j) { f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]; if(!c[i][j])f[i][j]++; } f[i][i+1]=f[i][i]; } for(int i=1;i<=t;++i){ int n=read(),m=read(); if(m>n)m=n; write(f[n][m]); putchar('\n'); } return 0; } ------------------------------------------------------ Problem1437: #include using namespace std; int main(){ int a[100001],l=1,r,i,j,k,m,n,s,ans,maxx,maxxx,t,ss,jj=1,s1,s2,s3; cin>>t; s=t; while(t--){ cin>>n; for(i=1;i<=n;i++){ cin>>a[i]; } s=a[1]; ss=a[1]; s1=1; s2=1; s3=1; for(i=2;i<=n;i++){ if(ss<0){ ss=a[i]; s3=i; } else{ ss=ss+a[i]; } if(ss>=s){ s=ss; s1=s3; s2=i; } } cout<<"Case "< } } ------------------------------------------------------ Problem1450: #include using namespace std; int main() { int a,b,c,d,ans=0,i,j,k,n,t; cin>>n; for(i=1;i<=n;i++) { ans+=i; } cout< } ------------------------------------------------------ Problem1453: #include using namespace std; int main() { long long n,i,j,k,t,f=0,m,b,p,c,mn,s=0,ss,r,ll; int a,d,e; cin>>a>>b>>c>>d>>e>>f; cout<
} ------------------------------------------------------ Problem1453: #include using namespace std; int i,s=0,n; int main() { for(i=0;i<6;i++) { cin>>n; s+=n; } cout< } ------------------------------------------------------ Problem1454: #include int main() { int i,j,k; int s; scanf("%d",&i); s=47*i; printf("%d\n",s); return 0; } ------------------------------------------------------ Problem1455: #include int main() { int i,j,k,maxx,minn,n,s; float ave; scanf("%d",&n); s=0; for(i=0;i { scanf("%d",&k); if(i==0) { maxx=k; minn=k; } else if(k>maxx) { maxx=k; } else if(k { minn=k; } s=s+k; } ave=s*1.0/n; printf("%d %d %.2f\n",maxx,minn,ave); return 0; } ------------------------------------------------------ Problem1456: #include using namespace std; int main() { int a,b,c,d,ans,i,j,k,n,t; cin>>n; for(i=0;i { for(j=0;j { cout<<"WIN"; } cout< } } ------------------------------------------------------ Problem1458: #include int main() { int t,i,x,j,n,m; scanf("%d",&t); while(t--) { x=0; scanf("%d %d",&n,&m); for(j=n;j<=m;j++) { for(i=2;i { if(j%i==0) { break; } } if(i==j) { x++; } } printf("%d\n",x); } } ------------------------------------------------------ Problem1460: #include using namespace std; int main() { long long n,i,j,k,t,f=0,m,b,p,c,s=0,ss,r,ll; long long a[1000],d,e; cin>>n; for(k=0;k { cin>>m; for(f=0;f { cin>>a[f]; } for(i=0;i { for(j=0;j { if(a[j]
{ c=a[j]; a[j]=a[j+1]; a[j+1]=c; } } } for(i=0;i { cout<
} cout< } } ------------------------------------------------------ Problem1462: #include