2012 jinhua

news/2024/7/5 21:19:48

2012 jinhua

I题:签到题,没什么意思。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int maxn=1000100;

int n;
int a[maxn];

int main()
{
    while(cin>>n&&n){
        int ans=0;
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            ans+=a[i]*a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}
View Code

J题:排列组合水题。

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

using namespace std;

const int maxn=1100;

typedef long long ll;
ll N,M,K;
ll P;
ll L[maxn],R[maxn];
char s[30];int x;
char t[30];int y;
bool visL[maxn][maxn],visR[maxn][maxn];

int main()
{
   // freopen("in.txt","r",stdin);
    while(cin>>N>>M>>K){
        if(N==0&M==0&K==0) break;
        cin>>P;
        memset(L,0,sizeof(L));
        memset(R,0,sizeof(R));
        memset(visL,0,sizeof(visL));
        memset(visR,0,sizeof(visR));
        while(P--){
            scanf("%s%d%s%d",s,&x,t,&y);
            if(t[0]=='p'&&!visL[x][y]) L[y]++,visL[x][y]=1;
            else if(!visR[x][y]) R[x]++,visR[x][y]=1;
        }
        ll cnt=0;
        for(int i=1;i<=M;i++){
            cnt+=L[i]*K+N*R[i]-L[i]*R[i];
        }
        cout<<N*M*K-cnt<<endl;
    }
    return 0;
}
View Code

A题:贪心。先比较两个的情况,推出贪心的依据,然后直接排序。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int maxn=1000100;

typedef long long ll;
int n;
const ll MOD=365*24*60*60;
struct NOde
{
    ll a,b;
    friend bool operator<(NOde A,NOde B)
    {
        return A.a*1.0*B.b<A.b*1.0*B.a;
    }
};
NOde Node[maxn];

int main()
{
   // freopen("in.txt","r",stdin);
    while(cin>>n&&n){
        for(int i=1;i<=n;i++){
            scanf("%lld%lld",&Node[i].a,&Node[i].b);
        }
        sort(Node+1,Node+n+1);
        ll res=0;
        for(int i=1;i<=n;i++){
            res=(res%MOD+((Node[i].a%MOD)+(Node[i].b%MOD)*(res%MOD))%MOD)%MOD;
        }
        cout<<res<<endl;
    }
    return 0;
}
View Code

D题:傻逼物理题。枚举角度,注意枚举的精度,少开变量,在纸上算出最终结果再写代码。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<math.h>

using namespace std;

const int maxn=1100;
const double Pi=acos(-1.0);
const double g=9.8;
const double EPS=0.0000000001;

typedef long long ll;

int N;
double H,L1,R1,L2,R2;
double v[maxn];

int main()
{
    //freopen("in.txt","r",stdin);
    while(cin>>N&&N){
        cin>>H>>L1>>R1>>L2>>R2;
        for(int i=1;i<=N;i++) scanf("%lf",&v[i]);
        int ans=0;
        for(double a=0;a<=Pi/2;a+=0.0002){
            int cnt=0;
            for(int i=1;i<=N;i++){
                double x=v[i]*cos(a)*(v[i]*sin(a)+sqrt(v[i]*v[i]*sin(a)*sin(a)+2*g*H))/g;
                if(x>L2-EPS&&x<R2+EPS){
                    cnt=0;break;
                }
                if(x>L1-EPS&&x<R1+EPS) cnt++;
            }
            ans=max(cnt,ans);
        }
        for(double a=0;a<=Pi/2;a+=0.0002){
            int cnt=0;
            for(int i=1;i<=N;i++){
                double x=v[i]*cos(a)*(-v[i]*sin(a)+sqrt(v[i]*v[i]*sin(a)*sin(a)+2*g*H))/g;
                if(x>L2-EPS&&x<R2+EPS){
                    cnt=0;break;
                }
                if(x>L1-EPS&&x<R1+EPS) cnt++;
            }
            ans=max(cnt,ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}
View Code

K题:傻逼模拟。

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

using namespace std;

const int maxn=1000100;

int N;
int x1,y1,x2,y2;
char d1,d2;
int s1,s2;
int t1,t2;
int K;

int goX(int x,char &dir,int s)
{
    if(dir=='S'){
        x=x+s;
        if(x>N){
            int c=x-N;
            int t=c/N;
            c%=N;
            if(t&1) x=c+1;
            else x=N-c,dir='N';
        }
        return x;
    }
    if(dir=='N'){
        x=x-s;
        if(x<1){
            int c=1-x;
            int t=c/N;
            c%=N;
            if(t&1) x=N-c;
            else x=c+1,dir='S';
        }
        return x;
    }
    return x;
}

int goY(int y,char &dir,int s)
{
    if(dir=='E'){
        y=y+s;
        if(y>N){
            int c=y-N;
            int t=c/N;
            c%=N;
            if(t&1) y=c+1;
            else y=N-c,dir='W';
        }
        return y;
    }
    if(dir=='W'){
        y=y-s;
        if(y<1){
            int c=1-y;
            int t=c/N;
            c%=N;
            if(t&1) y=N-c;
            else y=c+1,dir='E';
        }
        return y;
    }
    return y;
}

char Next(char dir)
{
    if(dir=='E') return 'N';
    if(dir=='N') return 'W';
    if(dir=='W') return 'S';
    if(dir=='S') return 'E';
}

int main()
{
    //freopen("in.txt","r",stdin);
    while(cin>>N&&N){
        x1=y1=1;x2=y2=N;
        cin>>d1>>s1>>t1>>d2>>s2>>t2;
        cin>>K;
        int t=1;
        for(int i=1;i<=K;i++){
            //cout<<d1<<" "<<d2<<endl;
            x1=goX(x1,d1,s1);
            y1=goY(y1,d1,s1);
            x2=goX(x2,d2,s2);
            y2=goY(y2,d2,s2);
            //cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<d1<<" "<<d2<<endl;
            if(x1==x2&&y1==y2){
                swap(d1,d2);
                continue;
            }
            if(t%t1==0) d1=Next(d1);
            if(t%t2==0) d2=Next(d2);
            t++;
        }
        cout<<x1<<" "<<y1<<endl;
        cout<<x2<<" "<<y2<<endl;
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/--560/p/4753039.html


http://www.niftyadmin.cn/n/1833223.html

相关文章

ORCLE 如何停止一个JOB【HOW TO STOP A JOB IN THE ORACLE】

为同事解决一个因为网络连接情况不佳时&#xff0c;执行一个超长时间的SQL插入操作。 既然网络状况不好&#xff0c;就选择了使用一次性使用JOB来完成该插入操作。在JOB执行一段时间后&#xff0c;我发现被插入表有些问题&#xff08;惭愧&#xff0c;当时也没有先检查检查…

贪心算法(求最优解)

小编开始自学&#xff0c;开始理解与学习算法&#xff0c;如果内容有误&#xff0c;欢迎大家评论&#xff0c;互动。 贪心算法&#xff08;Gre小编开始自学&#xff0c;开始理解与学习算法&#xff0c;如果内容有误&#xff0c;欢迎大家评论&#xff0c;互动。 贪心算法&#x…

算法入门笔记(一,介绍,递归)

小编认为算法是一个程序员必不可少的核心&#xff0c;所以从今天开始练习与加深学习。话不多说&#xff0c;开始学习。 时间复杂度&#xff1a;用来评估算法运行速率的式子。 一般情况下&#xff1a;时间复杂度高比复杂度底高&#xff08;通常条件一样情况下&#xff09; prin…

Spring Boot 系列(八)@ControllerAdvice 拦截异常并统一处理

Spring Boot 系列&#xff08;八&#xff09;ControllerAdvice 拦截异常并统一处理 在spring 3.2中&#xff0c;新增了ControllerAdvice 注解&#xff0c;可以用于定义ExceptionHandler、InitBinder、ModelAttribute&#xff0c;并应用到所有RequestMapping中。参考&#xff1…

java新手笔记25 日期格式化

1.系统时间 package com.yfs.javase;import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date;public class DateDemo1 {/*** 时间表示法*/public static void main(String[] args) {// long表示法long now System.currentTimeMi…

Quick Outline

为什么80%的码农都做不了架构师&#xff1f;>>> 快速大纲 作为一个developer&#xff0c;我们必须得学会一些快捷的方式&#xff0c;帮助自己快速的达到相应的目的。比如&#xff0c;我查看一个类&#xff0c;这个类定义了许多的方法&#xff0c;我不想去看outlin…

算法入门笔记(二,查找与排序)

继续学习算法&#xff0c;如果笔记对你有帮助&#xff0c;不要忘了点赞&#xff0c;如果有问题&#xff1f;希望大家批评指出。谢谢大家。 列表查找&#xff1a; 输入&#xff1a;列表与带查找元素 输出&#xff1a;元素下标&#xff08;未找到元素时一般返回None与-1&#xff…

Redis(@Cacheable、@CachePut、@CacheEvict 、@CacheConfig)

从3.1开始&#xff0c;Spring引入了对Cache的支持。其使用方法和原理都类似于Spring对事务管理的支持。Spring Cache是作用在方法上的&#xff0c;其核心思想是这样的&#xff1a;当我们在调用一个缓存方法时会把该方法参数和返回结果作为一个键值对存放在缓存中&#xff0c;等…