C
#include <bits/stdc++.h> using namespace std; int h[55], l[55], t, n, k; int main() { scanf("%d", &t); for (int cas = 1; cas <= t; ++cas) { if (cas != 1) puts(""); int ans = 0; scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) h[i] = l[i] = 0; for (int i = 1; i <= k; ++i) { int a, b; scanf("%d%d", &a, &b); if (h[a] && l[b]) ++ans; h[a] = l[b] = 1; } printf("Strategy #%d: %d\n", cas, ans); } return 0; }
D
#include<iostream> #include<cstdio> #include<set> #include<queue> #include<stack> #include<vector> #include<bitset> #include<cstring> #include<string> #include<algorithm> using namespace std; typedef long long ll; const int MAXN=1e5+10; inline int read(){ int x=0,y=1; char ch=getchar(); while(ch<‘0‘||ch>‘9‘){ if(ch==‘-‘){ y=-1; } ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*y; } int a[50]; int main(){ int T; T=read(); for(int t=1;t<=T;t++){ int n,m,it1=0,it2,it,ans,sum=0,DS,D,tmp; n=read();m=read(); for(int i=1;i<=n;i++){ a[i]=read(); sum+=a[i]; if(i<m) it1+=a[i]; } it2=it1+a[m]; DS=read(); cout<<"CD #"<<t<<":"<<endl; for(int ds=1;ds<=DS;ds++){ ans=0; D=read(); for(int d=1;d<=D;d++){ tmp=read(); if(d%2){ ans+=tmp; if(tmp%a[m]==0){ it=it2; } else{ it=tmp%a[m]+it1; } } else{ ans+=(tmp/sum)*a[m]; tmp%=sum; if(tmp<=it2-it){ ans+=tmp; } else{ ans+=it2-it; if(tmp>=sum-it+it1){ ans+=tmp-(sum-it+it1); } } it=(it+tmp)%sum; } } cout<<ans<<endl; } cout<<endl; } return 0; }
J
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #define Max 1000 using namespace std; int main(){ int n; cin>>n; for(int i=2;i<n;i++){ int x = n*i; int flag= 1; for(int j = 2;j<=sqrt(x);j++){ if((n*i)%(j*j)==0){ flag = 0; } } if(flag){ cout<<i<<endl; break; } } return 0; }
原文地址:https://www.cnblogs.com/aixiaodezsh/p/12616944.html
时间: 2024-11-07 22:08:37