SGU 146

题意:就是给你一个长度为l的圈,然后你跑步,每一段给你时间t和速度v,问你最后离起点多远

收获:就是把浮点数转为整数,然后但是会出现精度误差,比如l最多四位小数,那你就加0.00001这样

#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = ;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int main(){
double l;
ll n,t,v,L;
scanf("%lf%lld",&l,&n);
L = (l + 0.00001) * ;
ll ans = ;
rep(i,,n){
scanf("%lld%lld",&t,&v);
v*=;
ans += t * v;
ans %= L;
}
ans = min(ans,L - ans);
printf("%.6f",ans/10000.0);
return ;
}

SGU 179

题意:给你一个括号序列,然后问你他的下一个字典序的括号序列是什么 (<)

收获:我们考虑正常一个序列的下一个字典序列

比如 1 2 5 4 3

他的下一个字典序序列的构造是这个样的,从后往前找到第一个s[i]<s[i+1]的位置

然后交换s[i]后面序列中,稍稍比s[i]大的数字,在这里就是3,然后交换

变成 1 3 5 4 2,然后把s[i]后面的都变成最小字典序

变成 1 3 2 4 5

那么就勾出答案了,

那么对于括号序列,我们可以设)为1,(为0

按上面的构造方法,然后在维护构造的序列合法就行了,因为它初始化是合法的,那么我们改变后保证后面的位置的)大于(就行了,那么前面必然合法

#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 1e4+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
char s[maxn];
int dp[maxn][] = {};//0表示位置前面有多少个(,1表示位置前面有多少个)
int main(){
scanf("%s",s+);
int len = strlen(s+);
rep(i,,len+){
if(s[i]=='(') dp[i][]=dp[i-][]+;
else dp[i][]=dp[i-][];
if(s[i]==')') dp[i][]=dp[i-][]+;
else dp[i][]=dp[i-][];
}
bool ok = false;
repp(i,,len,) {
if(s[i]=='('&&s[i+]==')') continue;
ok = true;
}
if(!ok) return puts("No solution"),;
repd(i,len,){
if(s[i]==')'&&s[i-]=='('){
if(dp[len][]-dp[i][]>dp[len][]-dp[i][]){
swap(s[len],s[i-]);
sort(s+i,s+len+);
return printf("%s",s+),;
}
}
}
return ;
}

SGU 403

题意:提议比较难理解,就是找一个整数n,使得x*n小于1到n-1的和

收获:无

#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 1e5+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int main(){
int x;
cin>>x;
cout<<*x+<<endl;
return ;
}

最新文章

  1. Sublime 常用插件简介
  2. centos 安装 python2.7 运行webpy 项目
  3. JNDI全面总结
  4. Notification
  5. qsort函数用法【转】
  6. 用CSS box-shadow画画
  7. 高效渲染css
  8. BITED-Windows8应用开发学习札记之一:Win8应用开发入门
  9. 低压差稳压器AMS1585
  10. c-整型家族(integer family)
  11. 502 bad gateway是什么意思
  12. cocoa pods 安装 转载
  13. Apache新版配置虚拟主机的注意事项
  14. C#编写影院售票系统(A project with a higher amount of gold )(2:相关代码)
  15. thymeleaf 添加语法提示
  16. Codeforces 1080C- Masha and two friends
  17. CSS的background
  18. Docker(十一)-Docker commit创建镜像
  19. 【CUDA学习】__syncthreads的理解
  20. ELK日志系统之通用应用程序日志接入方案

热门文章

  1. 【Hibernate学习】 ——ORM(二)
  2. 12、NIO、AIO、BIO二
  3. android删除表和清空表
  4. centos7 配置redis
  5. 系统丢失的DLL文件问题根源解决(纯净官网下载放心)(图文详解)(博主推荐)
  6. java根据模板导出PDF(利用itext)
  7. 线程1—Runnable
  8. Windows Phone相关
  9. webpack 读取文件变量
  10. UVa 1001 Say Cheese【floyd】