[关闭]
@baobaobear 2020-05-28T09:37:56.000000Z 字数 5468 阅读 157

练习15

practise


A hesorchen

  1. /*
  2. * @Author: hesorchen
  3. * @Date: 2020-04-14 10:33:26
  4. * @LastEditTime: 2020-05-19 18:01:33
  5. * @Link: https://hesorchen.github.io/
  6. */
  7. #include <map>
  8. #include <set>
  9. #include <list>
  10. #include <queue>
  11. #include <deque>
  12. #include <cmath>
  13. #include <stack>
  14. #include <vector>
  15. #include <cstdio>
  16. #include <string>
  17. #include <cstring>
  18. #include <iostream>
  19. #include <algorithm>
  20. using namespace std;
  21. #define endl '\n'
  22. #define PI cos(-1)
  23. #define PB push_back
  24. #define ll long long
  25. #define INF 0x3f3f3f3f
  26. #define mod 998244353
  27. #define lowbit(abcd) (abcd & (-abcd))
  28. #define fre \
  29. { \
  30. freopen("in.txt", "r", stdin); \
  31. freopen("out.txt", "w", stdout); \
  32. }
  33. int main()
  34. {
  35. int a, b;
  36. cin >> a >> b;
  37. cout << a + b - 1 << endl;
  38. }

B hesorchen

  1. /*
  2. * @Author: hesorchen
  3. * @Date: 2020-04-14 10:33:26
  4. * @LastEditTime: 2020-05-19 18:04:16
  5. * @Link: https://hesorchen.github.io/
  6. */
  7. #include <map>
  8. #include <set>
  9. #include <list>
  10. #include <queue>
  11. #include <deque>
  12. #include <cmath>
  13. #include <stack>
  14. #include <vector>
  15. #include <cstdio>
  16. #include <string>
  17. #include <cstring>
  18. #include <iostream>
  19. #include <algorithm>
  20. using namespace std;
  21. #define endl '\n'
  22. #define PI cos(-1)
  23. #define PB push_back
  24. #define ll long long
  25. #define INF 0x3f3f3f3f
  26. #define mod 998244353
  27. #define lowbit(abcd) (abcd & (-abcd))
  28. #define fre \
  29. { \
  30. freopen("in.txt", "r", stdin); \
  31. freopen("out.txt", "w", stdout); \
  32. }
  33. int main()
  34. {
  35. ll n;
  36. cin >> n;
  37. ll ans = 0;
  38. ll s = INF;
  39. while (n--)
  40. {
  41. ll a;
  42. cin >> a;
  43. ans += a;
  44. s = min(s, ans);
  45. }
  46. cout << -s << endl;
  47. }

C 541907190117

  1. #include<set>
  2. #include<map>
  3. #include<list>
  4. #include<cmath>
  5. #include<stack>
  6. #include<queue>
  7. #include<cstdio>
  8. #include<cctype>
  9. #include<string>
  10. #include<vector>
  11. #include<climits>
  12. #include<cstring>
  13. #include<cstdlib>
  14. #include<iostream>
  15. #include<sstream>
  16. #include<algorithm>
  17. #define endl '\n'
  18. #define rtl rt<<1
  19. #define rtr rt<<1|1
  20. #define lson rt<<1, l, mid
  21. #define rson rt<<1|1, mid+1, r
  22. #define maxx(a, b) (a > b ? a : b)
  23. #define minn(a, b) (a < b ? a : b)
  24. #define zero(a) memset(a, 0, sizeof(a))
  25. #define INF(a) memset(a, 0x3f, sizeof(a))
  26. #define NIL(a) memset(a, -1, sizeof(a))
  27. #define IOS ios::sync_with_stdio(false)
  28. #define _test printf("============\n")
  29. using namespace std;
  30. typedef long long ll;
  31. typedef pair<int, int> P;
  32. typedef pair<ll, ll> P2;
  33. const double pi = acos(-1.0);
  34. const double eps = 1e-7;
  35. const ll MOD = 1000000007LL;
  36. const int INF = 0x3f3f3f3f;
  37. template<typename T> void read(T &x){
  38. x = 0;char ch = getchar();ll f = 1;
  39. while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
  40. while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
  41. }
  42. const int maxn = 1e2+10;
  43. int arr[maxn];
  44. int main() {
  45. int n;
  46. while(cin>>n && n) {
  47. stack<int> sk;
  48. for (int i = 1; i<=n; ++i) cin >> arr[i];
  49. int p = 1;
  50. for (int i = 1; i<=n; ++i) {
  51. sk.push(i);
  52. while(!sk.empty()&&sk.top()==arr[p]) {
  53. sk.pop(); ++p;
  54. }
  55. }
  56. cout << (p>n?"Yes":"No") << endl;
  57. }
  58. return 0;
  59. }

D yangzijiangac

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iostream>
  5. #include <map>
  6. #include <queue>
  7. #include <set>
  8. #include <cstring>
  9. #include <string>
  10. #include <cstdlib>
  11. #include <cmath>
  12. using namespace std;
  13. typedef long long ll;
  14. const int inf = 1 << 30;
  15. const int maxn = 2e5 + 5;
  16. const int N = 1e3 + 5;
  17. const int base = 131;
  18. string s1 = "xxxll", s2 = "xxlxll";
  19. int n, t, m;
  20. char s[maxn];
  21. int a[N], sum[N];
  22. int dp[N][2];
  23. int main()
  24. {
  25. ios::sync_with_stdio(false);
  26. cin.tie(0);
  27. int t;
  28. cin >> t;
  29. while (t--)
  30. {
  31. memset(dp,0,sizeof dp);
  32. cin >> s;
  33. int n = strlen(s);
  34. dp[0][1]=1;
  35. for (int i = 0; i < n; i++)
  36. {
  37. if(s[i]>='A'&&s[i]<='Z')
  38. {
  39. dp[i+1][1]=min(dp[i][1]+1,dp[i][0]+2);
  40. dp[i+1][0]=min(dp[i][1]+2,dp[i][0]+2);
  41. }
  42. else
  43. {
  44. dp[i+1][1]=min(dp[i][1]+2,dp[i][0]+2);
  45. dp[i+1][0]=min(dp[i][1]+2,dp[i][0]+1);
  46. }
  47. }
  48. cout<<min(dp[n][1]+1,dp[n][0])<<endl;
  49. }
  50. }

E yangzijiangac

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iostream>
  5. #include <map>
  6. #include <queue>
  7. #include <set>
  8. #include <cstring>
  9. #include <string>
  10. #include <cstdlib>
  11. #include <cmath>
  12. using namespace std;
  13. typedef long long ll;
  14. const int inf = 1 << 30;
  15. const int maxn = 2e5 + 5;
  16. const int N = 1e3 + 5;
  17. const int base = 131;
  18. string s1 = "xxxll", s2 = "xxlxll";
  19. int n, t, m;
  20. char s[maxn];
  21. int a[N], sum[N];
  22. int dp[N][2];
  23. int main()
  24. {
  25. ios::sync_with_stdio(false);
  26. cin.tie(0);
  27. ll n, k, c;
  28. cin >> n >> k >> c;
  29. if (k / n * n >= c)
  30. cout << c << endl;
  31. else
  32. cout << n - k / (k / n + 1) + c << endl;
  33. }

F

G 541907190117

  1. #include<set>
  2. #include<map>
  3. #include<list>
  4. #include<cmath>
  5. #include<stack>
  6. #include<queue>
  7. #include<cstdio>
  8. #include<cctype>
  9. #include<string>
  10. #include<vector>
  11. #include<climits>
  12. #include<cstring>
  13. #include<cstdlib>
  14. #include<iostream>
  15. #include<sstream>
  16. #include<algorithm>
  17. #define endl '\n'
  18. #define rtl rt<<1
  19. #define rtr rt<<1|1
  20. #define lson rt<<1, l, mid
  21. #define rson rt<<1|1, mid+1, r
  22. #define maxx(a, b) (a > b ? a : b)
  23. #define minn(a, b) (a < b ? a : b)
  24. #define zero(a) memset(a, 0, sizeof(a))
  25. #define INF(a) memset(a, 0x3f, sizeof(a))
  26. #define NIL(a) memset(a, -1, sizeof(a))
  27. #define IOS ios::sync_with_stdio(false)
  28. #define _test printf("============\n")
  29. using namespace std;
  30. typedef long long ll;
  31. typedef pair<int, int> P;
  32. typedef pair<ll, ll> P2;
  33. const double pi = acos(-1.0);
  34. const double eps = 1e-7;
  35. const ll MOD = 1000000007LL;
  36. const int INF = 0x3f3f3f3f;
  37. template<typename T> void read(T &x){
  38. x = 0;char ch = getchar();ll f = 1;
  39. while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
  40. while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
  41. }
  42. const int maxn = 1e3+10;
  43. char str[maxn];
  44. struct INFO {
  45. ll x, y, z;
  46. bool operator < (const INFO &k) const {
  47. if (x==k.x) return y==k.y ? z>k.z : y<k.y;
  48. return x<k.x;
  49. }
  50. } info[maxn];
  51. vector<INFO> ve;
  52. ll a[3], dp[maxn];
  53. void join() {
  54. sort(a, a+3);
  55. ve.push_back({a[0],a[1],a[2]});
  56. ve.push_back({a[0],a[2],a[1]});
  57. ve.push_back({a[1],a[0],a[2]});
  58. ve.push_back({a[1],a[2],a[0]});
  59. ve.push_back({a[2],a[1],a[0]});
  60. ve.push_back({a[2],a[0],a[1]});
  61. }
  62. int main() {
  63. int n; int kase = 1;
  64. while(~scanf("%d", &n) && n) {
  65. for (int i = 1; i<=n; ++i) {
  66. scanf("%d%d%d", &a[0], &a[1], &a[2]);
  67. join();
  68. }
  69. sort(ve.begin(),ve.end());
  70. //for (int i = 0; i<6*n; ++i) printf("%d %d %d\n", ve[i].x, ve[i].y, ve[i].z);
  71. ll ans = 0;
  72. for (int i = 0; i<6*n; ++i) {
  73. dp[i] = 0;
  74. for (int j = i-1; j>=0; --j)
  75. if (ve[i].x>ve[j].x&&ve[i].y>ve[j].y)
  76. dp[i] = max(dp[i], dp[j]);
  77. //cout << ve[i].z << endl;
  78. dp[i] += ve[i].z;
  79. //cout << dp[i] << endl;
  80. ans = max(ans, dp[i]);
  81. }
  82. printf("Case %d: maximum height = %d\n", kase++, ans);
  83. ve.clear(); zero(dp);
  84. }
  85. return 0;
  86. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注