2017 7.25多校训练第一场补题

 

 一题签到 -1 和不减的位数相同,故可简化

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main(){
 5     int n;
 6     int k=1;
 7     while(cin>>n){
 8         ll ans=n*log(2)/log(10);
 9         printf("Case #%d: %lld\n",k++,ans);
10     }
11 }
View Code

 

 

 

6040 解题关键:nth_element的使用,注意将区间可以缩小,以及int和unsigned之间直接转化会出错。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 unsigned rating[10000009];
 5 unsigned ans[188];
 6 struct node{
 7     int id;
 8     int ra;
 9 }arr[199];
10 bool cmp(node &a,node &b){
11     return a.ra>b.ra;
12 }
13 unsigned x,y,z;
14 unsigned rng61(){
15       unsigned t;
16       x ^= x << 16;
17       x ^= x >> 5;
18       x ^= x << 1;
19       t = x;
20       x = y;
21       y = z;
22       z = t ^ x ^ y;
23       return z;
24 }
25 int main(){
26     int n,m;
27     unsigned a,b,c;
28     int k=1;
29     while(scanf("%d%d%u%u%u",&n,&m,&a,&b,&c)!=EOF){
30         x=a,y=b,z=c;
31         for(int i=0;i<m;i++)     {cin>>arr[i].ra;arr[i].id=i;} 
32         for(int i=0;i<n;i++)    rating[i]=rng61();
33         sort(arr,arr+m,cmp);
34         int temp=n;
35         for(int i=0;i<m;i++){
36             nth_element(rating,rating+arr[i].ra,rating+temp);
37             temp=arr[i].ra;
38             ans[arr[i].id]=rating[temp];
39         }
40         printf("Case #%d: ",k++);
41         for(int i=0;i<m;i++){
42             printf("%u%c",ans[i],i==m-1?'\n':' ');
43         }
44     }
45     return 0;
46 }
View Code

 

弱渣待补。

 

另一签到:1010 找规律

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main(){
 5     ll n,k,t;
 6     int tt=1;
 7     while(cin>>n>>k){
 8         if(n==2){
 9             ll ans;
10              t=k%n;
11             if(t==0) ans=2;
12             else ans=1;
13             printf("Case #%d: %lld\n",tt++,ans);
14             continue;
15         }
16         
17         ll t1=(k-n)%(n-1),t2=(k-n)/(n-1);
18         ll ans;
19         if(k<=n) ans=k;
20         else{
21             if(t2%2==0&&t1==0){
22                 ans=n;
23             }
24             else if(t2%2==1&&t1==0){
25                 ans=n-1;
26             }
27             else{
28                 ans=t1;
29             }
30         }
31         printf("Case #%d: %lld\n",tt++,ans);
32     }
33 }
View Code

 

posted @ 2017-07-27 01:06  Elpsywk  阅读(242)  评论(0编辑  收藏  举报