福建工程学院第七届ACM程序设计新生赛 (同步赛)

A.关电脑

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 int T,h1,m1,s1,h2,m2,s2,t1,t2,ans;
 5 int main(){
 6     while(cin>>T){
 7         for(int cas=1;cas<=T;++cas){
 8             cin>>h1>>m1>>s1>>h2>>m2>>s2;
 9             t1=h1*3600+m1*60+s1,t2=h2*3600+m2*60+s2;
10             ans=t2-t1+(t1>=t2?24*3600:0);
11             cout<<"Case #"<<cas<<": "<<ans<<endl;
12         }
13     }
14     return 0;
15 }
View Code

B.保护环境:大的矩形面积减去三个直角三角形的面积即可。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 double a,b;
 5 int main(){
 6     while(cin>>a>>b){
 7         cout<<setiosflags(ios::fixed)<<setprecision(2)<<(a+b)*a-a*a/2-(a+b)*b/2-(a-b)*b/2<<endl;
 8     }
 9     return 0;
10 }
View Code

C.车厘子的守护士兵1.0

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=1005;
 5 int n,L,R,l[maxn],r,ans;
 6 int main(){
 7     while(cin>>n>>L>>R){
 8         ans=0;
 9         for(int i=1;i<=n;++i)cin>>l[i];
10         for(int i=1;i<=n;++i){
11             cin>>r;
12             if((L<=i&&i<=R)&&(l[i]<=L&&R<=r))ans++;
13         }
14         cout<<ans<<endl;
15     }
16     return 0;
17 }
View Code

D.内心里的一把火:向量叉积求三角形面积,将以P为起点与之相连的三个三角形面积之和与A、B、C三点构成的三角形面积进行比较即可--->相关博文:向量叉积的运用

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 struct node{int x,y;}nod[5];
 4 int a,b,sum,tmp;
 5 inline int cross(node p0,node p1,node p2){
 6     return abs((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
 7 }
 8 int main(){
 9     while(cin>>nod[0].x>>nod[0].y>>nod[1].x>>nod[1].y>>nod[2].x>>nod[2].y){
10         cin>>nod[3].x>>nod[3].y,sum=0;
11         for(int i=1;i<=3;++i)sum+=cross(nod[3],nod[i-1],nod[i%3]);
12         tmp=cross(nod[0],nod[1],nod[2]);
13         puts(sum!=tmp?"NO":"YES");
14     }
15     return 0;
16 }
View Code

E.分配物资

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn=1e6+5;
 5 int n,m,q,x,y,z,a[maxn],ans[maxn];bool flag[maxn];
 6 int main(){
 7     while(cin>>n>>m>>q){
 8         memset(ans,0,sizeof(ans));
 9         memset(flag,false,sizeof(flag));
10         memset(a,0,sizeof(a));
11         for(int i=1;i<=n;++i)cin>>a[i];
12         for(int i=1;i<=m;++i){
13             cin>>x>>y;
14             if(a[x]>=y)///物资充足
15                 flag[i]=true,a[x]-=y;
16             else ans[i]=y-a[x],a[x]=0;///同时置0
17         }
18         while(q--){
19             cin>>z;
20             if(flag[z])puts("Yes");
21             else cout<<ans[z]<<endl;
22         }
23     }
24     return 0;
25 }
View Code

F.吃饭啦

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1005;
 4 int n,m,a[maxn],x,q,ans,pos;
 5 int main(){
 6     while(cin>>n>>m){
 7         memset(a,0,sizeof(a));
 8         for(int i=0;i<m;++i)cin>>a[i];
 9         sort(a,a+m);
10         cin>>q;
11         for(int i=1;i<=q;++i){
12             cin>>x;
13             pos=lower_bound(a,a+m,x)-a;
14             ///cout<<"os:"<<pos<<endl;
15             if(pos==m)cout<<x-a[pos-1]<<endl;///找不到,则为x-a[pos-1]
16             else if(a[pos]==x)puts("0");///如果在某点上,则为0
17             else if(!pos)cout<<a[0]-x<<endl;///如果比第1个点位置小,则为a[0]-x
18             else cout<<min(a[pos]-x,x-a[pos-1])<<endl;///否则就取到两边绝对值最小的即可
19         }
20     }
21     return 0;
22 }
View Code

G.MOXIN_ZUMA

H.约会

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 LL x,y,a,z;
 5 int main(){
 6     while(cin>>x>>y>>a){
 7         if(x<0)x=-x;
 8         if(y<0)y=-y;
 9         z=max(x,y);
10         if((x+y)&1)puts("Not the fate");
11         else if((!x&&!y&&a)||(a<z)||((a-z)&1))puts("You are lying");
12         else puts("We are together");
13     }
14     return 0;
15 }
View Code

I.这是一个沙雕题I

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char str[105];int k,fuck,cnt[26];string ans,tmp;bool flag;
 4 int main(){
 5     while(cin>>k){
 6         cin>>str,memset(cnt,0,sizeof(cnt)),ans=tmp="",flag=false,fuck=strlen(str);
 7         for(int i=0;str[i];++i)cnt[str[i]-'a']++;
 8         for(int i=0;i<26;++i)
 9             if(cnt[i]&&cnt[i]%k!=0)flag=true;///如果不能被k整除,那么肯定不能构成k个相同的字符串
10         if(flag){puts("-1");continue;}
11         for(int i=0;i<26;++i){
12             if(cnt[i]){///单个字符串拥有该字母的个数为cnt[i]/k
13                 for(int j=1;j<=cnt[i]/k;++j)tmp+=i+'a';
14             }
15         }
16         while(k--)ans+=tmp;///重复k次表示重新排列
17         cout<<ans<<endl;
18     }
19     return 0;
20 }
View Code

J.这是一个沙雕题II

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 LL n,k,ans,tmp1,tmp2,cnt1,cnt2,i,a[20],b[20],c[20]={1};
 5 int main(){
 6     for(i=1;i<19;++i)c[i]=c[i-1]*10;///预处理10^i
 7     while(cin>>n>>k){
 8         ans=tmp1=n,tmp2=n-k,cnt1=cnt2=0;
 9         while(tmp1)a[cnt1++]=tmp1%10,tmp1/=10,b[cnt2++]=tmp2%10,tmp2/=10;
10         for(i=cnt1-1;i>=0&&a[i]==b[i];--i);///遇到第一位不相等就退出,剩下的每一位填9
11         if(i>0&&((n+1LL)%c[i]))ans=n-n%c[i]-1;///前提是至少要在十位上出现不同即i>0,此种情况下才能得到9
12         cout<<ans<<endl;///否则输出原本的数字
13     }
14     return 0;
15 }
View Code

K.这是一个沙雕题III

猜你喜欢

转载自www.cnblogs.com/acgoto/p/10151167.html