CSU 1378: Shipura 1383: A Easy Problem 1390: Planting Trees 1391: Boiling Vegetables

1378: Shipura

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
 
using namespace std;
 
typedef long long ll;
 
const ll MOD = (ll)1e9+7;
const int MAXN = (int)2e6+9;
 
stack<ll> num;
stack<char> op;
 
char str[MAXN];
char str2[MAXN];
 
inline ll S(ll x) {
    return (x*x)%MOD;
}
 
void pushNum(ll x) {
    while (!op.empty() && '^'==op.top()) { //其实这个用if就好了,因为>>运算时先计算左边,所以栈中不会出现连续的>>运算
        op.pop();
        ll tmp = num.top(); num.pop();
        if (x>60) {
            tmp = 0;
            x = 0;
        }
        x = (tmp>>x);
    }
    num.push(x);
}
 
void slove() {
    int i = 0;
    ll tmp;
    while (true) {
        if ('\0'==str[i]) break;
 
        while (' '==str[i]) i++;
 
        if ('S'==str[i]) {
            op.push('S');
            i++;
            continue;
        }
        if ('<'==str[i]) {
            i++;
            continue;
        }
        if ('0'<=str[i]&&str[i]<='9') {
            tmp = 0;
            while ('0'<=str[i]&&str[i]<='9') {
                tmp *=10;
                tmp += str[i]-'0';
                i++;
            }
            pushNum(tmp);
            continue;
        }
        if ('>'==str[i]) {
            if ('>'==str[i+1] && ('S'==str[i+2] || ('0'<=str[i+2]&&str[i+2]<='9'))) {
                op.push('^');
                i++;
            }else if ('S'==op.top()) {
                op.pop();
                tmp = num.top(); num.pop();
                pushNum(S(tmp));
            }
            i++;
            continue;
        }
    }
    printf("%lld\n", num.top());
}
 
void Transform(){
    int i = 0, j = 0;
    while (true) {
        if ('\0'==str2[i]) break;
        if (' '==str2[i]) while (' '==str2[i]) i++;
        else {
            str[j++] = str2[i++];
        }
    }
    str[j] = '\0';
}
 
int main()
{
    #ifdef Phantom01
        freopen("CSU1378.txt", "r", stdin);
    #endif // Phantom01
 
    while (gets(str2)) {
        if ('#'==str2[0]&&'\0'==str2[1]) break;
 
        while (!num.empty()) num.pop();
        while (!op.empty()) op.pop();
 
        Transform();
        slove();
    }
 
    return 0;
}
/**********************************************************************
	Problem: 1378
	User: 3901140225
	Language: C++
	Result: AC
	Time:48 ms
	Memory:5932 kb
**********************************************************************/

1383: A Easy Problem


#include <cstdio>
#include <iostream>
#include <algorithm>
#define LL long long
#define ULL unsigned long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
#define N 10100
#define INF 0x3f3f3f3f
#define eps 1e-9 
using namespace std;
ULL gcd(ULL a,ULL b){
    return (b==0?a:gcd(b,a%b));
}
ULL nume[20000],demo[10000];
int main()
{
    ULL a,b,c,t,cnt1,cnt2,i,j;
    cin>>t;
    while(t--){
        cin>>a>>b;
        c=1;
        cnt1=cnt2=0;
        if(a==b||b==0){
            cout<<1<<endl;
            continue;
        }
        if(b==a-1||b==1){
            cout<<a<<endl;
            continue; 
        } 
        b=min(b,a-b); 
        for(i=a-b+1;i<=a;++i){
            nume[cnt1++]=i;
        }
        for(i=2;i<=b;++i){
            demo[cnt2++]=i;
        }
        for(i=0;i<cnt2;++i){
            for(j=0;demo[i]!=1&&j<cnt1;++j){
                ULL n=gcd(demo[i],nume[j]);
                demo[i]/=n;
                nume[j]/=n;
            }
        }
        for(int i=0;i<cnt1;++i){
            c*=nume[i];
        }
        cout<<c<<endl;
    }
    return 0;
}
/**********************************************************************
	Problem: 1383
	User: 3901140225
	Language: C++
	Result: AC
	Time:8 ms
	Memory:2256 kb
**********************************************************************/

1390: Planting Trees


#include <iostream>  
#include <algorithm>  
#include <cstdio>  
using namespace std;  
  
int a[100100];  
  
bool cmp(int a, int b) {  
    return a > b;  
}  
int main()  
{  
    int n;  
    cin >> n;  
    for(int i = 0; i < n; i++) {  
        scanf("%d", &a[i]);  
    }  
    sort(a, a+n, cmp);  
    int max = 0;  
    for(int i = 0; i < n; i++) {  
        a[i] = a[i] + i + 2;  
        if(max < a[i]) max = a[i];  
    }  
    printf("%d\n", max);  
    return 0;  
}  
/**********************************************************************
	Problem: 1390
	User: 3901140225
	Language: C++
	Result: AC
	Time:44 ms
	Memory:2412 kb
**********************************************************************/



1391: Boiling Vegetables



#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

double vagetable[1100],limit;
int n;

int main()
{
    cin>>limit>>n;
    for(int i=0;i<n;i++) cin>>vagetable[i];

    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }

    sort(vagetable,vagetable+n,less<double>());

    int ans=501;

    for(int i=0;i<n;i++)
    {
        for(int c=0;c<ans;c++)
        {
            double maxsize=vagetable[i]/(c+1);
            double minsize=maxsize*limit;

            int temp=c;
            bool flag=true;

            for(int j=0;j<n;j++)
            {
                if(i==j) continue;

                int c1=(int)ceil(vagetable[j]/maxsize)-1;

                if(vagetable[j]/(c1+1) < minsize)
                {
                    flag=false; break;
                }
                temp+=c1;
                if(temp>=ans)
                {
                    flag=false; break;
                }
            }
            if(flag)
            {
                ans=min(ans,temp);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


/**********************************************************************
	Problem: 1391
	User: 3901140225
	Language: C++
	Result: AC
	Time:44 ms
	Memory:2032 kb
**********************************************************************/

猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80233562
今日推荐