[关闭]
@baobaobear 2020-04-21T12:58:58.000000Z 字数 4017 阅读 231

练习1

practise


A Kevin7Zz

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <queue> //priority_queue
  6. #include <map>
  7. #include <set> //multiset set<int,greater<int>>大到小
  8. #include <vector>// vector<int>().swap(v);清空释放内存
  9. #include <stack>
  10. #include <cmath> // auto &Name : STLName Name.
  11. #include <utility>
  12. #include <sstream>
  13. #include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
  14. #define mod 1000000007
  15. #define mod9 998244353
  16. typedef unsigned long long ull;
  17. typedef long long ll;
  18. typedef double db;
  19. typedef long double ld;
  20. const db eps=1e-10;
  21. const int INF = 0x3f3f3f3f;
  22. const ll inf=0x3f3f3f3f3f3f3f3f;
  23. #define rep(i,be,en) for (int i=be;i<=en;i++)
  24. #define per(i,be,en) for (int i=en;i>=be;i--)
  25. using namespace std;
  26. const int N=1e5+7;
  27. char a;
  28. int i,j,n,m=0;
  29. int main(){
  30. while(~scanf("%c",&a)&&a!='@'){
  31. scanf("%d",&n);
  32. getchar();
  33. if(m++){
  34. printf("\n");
  35. }
  36. for(i=0;i<n;i++){
  37. for(j=0; j<n-1-i; j++)
  38. printf(" ");
  39. for(j=0; j<2*i+1; j++)
  40. if(i==n-1)
  41. printf("%c",a);
  42. else if(j==0||j==2*i)
  43. printf("%c",a);
  44. else
  45. printf(" ");
  46. printf("\n");
  47. }
  48. }
  49. return 0;
  50. }

B WAwhatWA

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  6. int n , m , k;
  7. cin >> n >> m >> k;
  8. puts(((n+m+k)&1)?"win":"lose");
  9. return 0;
  10. }

C 1292224662

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for(int i=a;i<=n;i++)
  4. #define per(i,a,n) for(int i=n;i>=a;i--)
  5. #define pb push_back
  6. #define SZ(x) ((int)(x).size())
  7. typedef long long ll;
  8. typedef pair<int,int> pii;
  9. typedef double db;
  10. pii a[10010];
  11. int n,ans;
  12. int main(){
  13. cin>>n;
  14. rep(i,1,n){
  15. cin>>a[i].first;
  16. a[i].second=i;
  17. }
  18. sort(a+1,a+1+n);
  19. rep(i,1,n){
  20. ans+=abs(a[i].second-i);
  21. }
  22. cout<<ans<<endl;
  23. return 0;
  24. }

D 2018031701054

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstring>
  5. using namespace std;
  6. const int N = 7 + 2e5;
  7. int a[N];
  8. int n;
  9. int main() {
  10. cin >> n;
  11. for (int i = 1; i <= n; ++i)
  12. cin >> a[i];
  13. int ans = 0;
  14. sort(a + 1, a + n + 1);
  15. for (int i = 1; i <= n; ++i) {
  16. int pos = i;
  17. for (int j = a[i] + a[i]; ; j += a[i]) {
  18. pos = lower_bound(a + pos, a + n + 1, j) - a;
  19. ans = max(ans, a[pos - 1] % a[i]);
  20. if (pos > n) break;
  21. }
  22. }
  23. cout << ans << endl;
  24. return 0;
  25. }

E 1292224662

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for(int i=a;i<=n;i++)
  4. #define per(i,a,n) for(int i=n;i>=a;i--)
  5. #define pb push_back
  6. #define SZ(x) ((int)(x).size())
  7. typedef long long ll;
  8. typedef pair<int,int> pii;
  9. typedef double db;
  10. void gg(int x,vector<pii>& v){
  11. rep(i,1,x){
  12. rep(j,i,x){
  13. if(i*i+j*j==x*x){
  14. v.pb({i,j});
  15. }
  16. }
  17. }
  18. }
  19. int xx,yy;
  20. vector<pii> v1,v2;
  21. pii p1,p2;
  22. int main(){
  23. cin>>xx>>yy;
  24. gg(xx,v1);gg(yy,v2);
  25. if((int)v1.size()==0||(int)v2.size()==0){
  26. puts("NO");
  27. return 0;
  28. }
  29. else{
  30. for(auto p1:v1){
  31. for(auto p2:v2){
  32. if(p1.second<p1.first){
  33. swap(p1.first,p1.second);
  34. }
  35. if(p2.second<p2.first){
  36. swap(p2.first,p2.first);
  37. }
  38. if(p1.first*p2.second==p2.first*p1.second){
  39. if(p1.second==p2.first){
  40. swap(p1.first,p1.second);
  41. swap(p2.first,p2.second);
  42. }
  43. printf("YES\n0 0\n%d %d\n%d %d\n",p1.first,p1.second,-p2.second,p2.first);
  44. return 0;
  45. }
  46. }
  47. }
  48. puts("NO");
  49. }
  50. return 0;
  51. }

F

G 1292224662

  1. #include<iostream>
  2. #include<map>
  3. #include<cstdio>
  4. using namespace std;
  5. int t,n,u,v,e,flag;
  6. int fa[200010],p;
  7. int s1[200010],s2[200010],q;
  8. map<int,int> mp;
  9. int fnd(int x){
  10. if(x==fa[x]) return x;
  11. else return fa[x]=fnd(fa[x]);
  12. }
  13. void merge(int x,int y){
  14. fa[fnd(x)]=fnd(y);
  15. return ;
  16. }
  17. int assign(int x){
  18. if(mp[x]){
  19. return mp[x];
  20. }
  21. else{
  22. mp[x]=++p;
  23. return mp[x];
  24. }
  25. }
  26. int main(){
  27. scanf("%d",&t);
  28. while(t--){
  29. scanf("%d",&n);
  30. flag=0;p=0;q=0;
  31. mp.clear();
  32. for(int i=1;i<=2*n+5;i++){
  33. fa[i]=i;
  34. }
  35. for(int i=1;i<=n;i++){
  36. scanf("%d%d%d",&u,&v,&e);
  37. if(e){
  38. merge(assign(u),assign(v));
  39. }
  40. else{
  41. ++q;s1[q]=u;s2[q]=v;
  42. }
  43. }
  44. for(int i=1;i<=q;i++){
  45. if(s1[i]==s2[i]){
  46. flag=1;
  47. break;
  48. }
  49. if(mp[s1[i]]==0||mp[s2[i]]==0){
  50. continue;
  51. }
  52. if(fnd(mp[s1[i]]) == fnd(mp[s2[i]])){
  53. flag=1;
  54. break;
  55. }
  56. }
  57. if(flag){
  58. puts("NO");
  59. }
  60. else{
  61. puts("YES");
  62. }
  63. }
  64. return 0;
  65. }

H

I 1292224662

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define rep(i,a,n) for(int i=a;i<=n;i++)
  4. #define per(i,a,n) for(int i=n;i>=a;i--)
  5. #define pb push_back
  6. #define SZ(x) ((int)(x).size())
  7. typedef long long ll;
  8. typedef pair<int,int> pii;
  9. typedef double db;
  10. const int mod=1e9+7;
  11. int dp[5010][5010],sum[5010][5010];
  12. char a[5010],b[5010];
  13. int main(){
  14. scanf("%s",a+1);
  15. scanf("%s",b+1);
  16. int n=strlen(a+1),m=strlen(b+1);
  17. rep(i,1,n){
  18. rep(j,1,m){
  19. if(a[i]==b[j]){
  20. dp[i][j]=1+sum[i-1][j-1];
  21. dp[i][j]%=mod;
  22. }
  23. }
  24. rep(j,1,m){
  25. sum[i][j]=sum[i][j-1]+dp[i][j];
  26. sum[i][j]%=mod;
  27. }
  28. }
  29. ll ans=0;
  30. rep(i,1,n){
  31. rep(j,1,m){
  32. ans+=dp[i][j];
  33. ans%=mod;
  34. }
  35. }
  36. cout<<ans<<endl;
  37. return 0;
  38. }

J

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注