Solitude пре 5 година
родитељ
комит
1bd7fa771a
4 измењених фајлова са 118 додато и 0 уклоњено
  1. 32 0
      F.cpp
  2. 21 0
      G.cpp
  3. 42 0
      H2.cpp
  4. 23 0
      I.cpp

+ 32 - 0
F.cpp

@@ -0,0 +1,32 @@
+#include<bits/stdc++.h>
+using namespace std;
+const int MAX=100005;
+struct node{
+    int s;
+    int e;
+}a[MAX];
+
+int n;
+bool cmp(node x,node y)
+{
+    return x.e<y.e;
+}
+int main()
+{
+    while(cin>>n,n)
+    {
+        for(int i=0;i<n;i++)
+            scanf("%d %d",&a[i].s,&a[i].e);
+        sort(a,a+n,cmp);
+        int temp=a[0].e,counter=1;
+        for(int i=1;i<n;i++)
+        {
+            if(a[i].s>=temp)
+            {
+                counter++;
+                temp=a[i].e;
+            }
+        }
+       printf("%d\n",counter);
+    }
+}

+ 21 - 0
G.cpp

@@ -0,0 +1,21 @@
+#include<bits/stdc++.h>
+using namespace std;
+int main()
+{
+    int T;
+    while(cin>>T)
+    {
+        for(int i=0; i<T; i++)
+        {
+            char str[1000];
+            cin>>str;
+            if(!strcmp(str,"bowl")||!strcmp(str,"knife")||!strcmp(str,"fork")||!strcmp(str,"chopsticks"))
+                if(i==T-1)
+                    cout<<str;
+                else
+                    cout<<str<<" ";
+        }
+        cout<<endl;
+    }
+    return 0;
+}

+ 42 - 0
H2.cpp

@@ -0,0 +1,42 @@
+#include<bits/stdc++.h>
+using namespace std;
+const int maxn = 1e5 + 5;
+int f[maxn];
+int main()
+{
+    int s, x1, x2;
+    int t1, t2;
+    int p, d;
+    cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;
+    int ans = abs(x2 - x1) * t2;
+    int to = x2 - x1;
+    if(to < 0) to = -1;
+    else to = 1;
+    if(to == 1)
+    {
+        if(d == 1)
+        {
+            if(p <= x1) ans = min((x2 - p) * t1, ans);
+            else ans = min((s - p + s + x2) * t1, ans);
+        }
+        else
+        {
+            ans = min(ans, (p + x2) * t1);
+        }
+
+    }
+    else
+    {
+        if(d == -1)
+        {
+            if(p >= x1) ans = min((p - x2) * t1, ans);
+            else ans = min((p + s + s - x2) * t1,ans);
+        }
+        else
+        {
+            ans = min(ans, (s - p + s - x2) * t1);
+        }
+    }
+    cout << ans << endl;
+    return 0;
+}

+ 23 - 0
I.cpp

@@ -0,0 +1,23 @@
+#include <bits/stdc++.h>
+using namespace std;
+int dp[31][20001];
+int main()
+{
+    int v, n;
+    cin >> v >> n;
+    for(int i = 1; i <= n; i++)
+    {
+        int t;
+        cin >> t;
+        for(int j = 1; j <= v; j++)
+        {
+            if (j >= t)
+                dp[i][j] = max(dp[i-1][j], dp[i-1][j-t] + t);
+            else
+                dp[i][j] = dp[i-1][j];
+        }
+    }
+    cout << v - dp[n][v] <<endl;
+    return 0;
+}
+