185div2

/*

A题,简单题 

*/
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

bool judge(string s,string s1){
    if(s.size()<s1.size()) return false;
    for(int i=s1.size()-1, j=s.size()-1;i>=0;i--,j--)
        if(s1[i]!=s[j]) return false;
    return true;
}

bool judge1(string s,string s1){
    if(s.size()<s1.size()) return false;
    for(int i=0, j=0;i<s1.size();i++,j++)
        if(s1[i]!=s[j]) return false;
    return true;
}

int main(){
    int t;
    cin>>t;
    getchar();
    string s1="lala.",s2="miao.";
    while(t--){
        string s;
        getline(cin,s);
        bool p=judge(s,s1);
        bool q=judge1(s,s2);
        if( p&&q ) { cout<<"OMG>.< I don't know!"<<endl; continue; }
        if( p ) { cout<<"Freda's"<<endl; continue; }
        if( q ) { cout<<"Rainbow's"<<endl; continue; }
        cout<<"OMG>.< I don't know!"<<endl;
    }
}

 

B 公式索引资料,可以自己推导公式

急,在线等!A,B,C三个人按顺序扔硬币,第一个扔到正面的人赢,问三个人赢的概率分别是多少?

2010-09-14 02:00 AMANDA89|分类:数学|浏览447

三个人的概率不一样啊!!!
注意,是三个人按顺序扔硬币。
要写出原因和步骤啊。
也不可能是1/2,1/41/8,加起来不等于一。如果第一轮大家都没扔到正面,就有第二轮了啊。

提问者采纳

2010-09-14 02:17

先讨论第一轮:
A
赢得概率是1/2
B
赢得概率是(1/2)^2=1/4
C
赢的概率是(1/2)^3=1/8

如果都没赢,第二轮:
A
赢得概率是(1/2)^4=1/16
B
赢得概率是(1/2)^5=1/32
C
赢的概率是(1/2)^6=1/64
 

所以总的:
A
赢得概率是1/2+1/16+1/128+。。。,   无限多个不好算,但有办法
B
赢得概率是1/4+1/32+。。。。    =1/2×A的概率
C
赢的概率是1/8+1/64+。。。。    =1/4×A的概率

那么就有
A+B+C=7/4*A=1
A=4/7
B=2/7
C=1/7

#include<iostream>
#include<cmath>
using namespace std;

int main(){
    double a,b,c,d;
    while(cin>>b>>a>>d>>c){
        cout<<b*c/( b*c + d*(a-b))<<endl;
    }
}

/* 

C 水题 

*/ 
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
    int n,k;
    while(cin>>n>>k){
        if(n*(n-1)/2 <= k) cout<<"no solution"<<endl;
        else 
            for(int i=0;i<n;i++)
                printf("0 %d\n",i);
    }
} 

<think>我们将讨论如何使用CSS实现一个div的完美缩放。完美缩放通常指的是保持元素的宽高比,同时根据容器或视口的大小进行调整。常见的应用场景包括响应式图片、视频嵌入、卡片等。 实现方法: 1. 使用padding-top(或padding-bottom)技巧:利用padding的百分比是相对于宽度计算的特性,可以创建一个固定宽高比的容器。 2. 使用视口单位(vw, vh):根据视口的宽度或高度来设置元素尺寸,但要注意保持宽高比。 3. 使用CSS的aspect-ratio属性(较新的属性,现代浏览器支持):直接设置宽高比。 我们将分别介绍这些方法。 方法1:padding-top技巧 假设我们要实现一个16:9的宽高比,我们可以这样: - 设置容器的宽度为100%(或任意宽度,但需要是相对于父元素的百分比) - 然后设置padding-top为56.25%(因为9/16=0.5625,即56.25%) 这样,容器的高度将由padding-top撑开,形成16:9的比例。 方法2:视口单位 我们可以设置宽度为100vw,高度为56.25vw(同样对于16:9)。但是这种方法的问题在于,如果视口高度很小,可能会超出视口。所以通常结合使用max-width和max-height。 方法3:aspect-ratio属性(推荐,但需注意浏览器兼容性) 我们可以直接设置:aspect-ratio: 16/9; 下面我们分别给出代码示例: 方法1示例: 使用padding-top技巧,并在内部放置一个绝对定位的内容区域,这样内容可以完美适应容器。 方法2示例: 使用vw单位,但可能不够灵活,因为高度依赖于宽度,而容器大小可能不一定是视口大小。 方法3示例: 直接使用aspect-ratio属性,简单直接。 我们将主要展示方法1(兼容性好)和方法3(现代且简单)。 方法1:padding-top技巧 HTML结构: <div class="container"> <div class="content">内容</div> </div> CSS: .container { width: 100%; position: relative; padding-top: 56.25%; /* 16:9 Aspect Ratio */ } .content { position: absolute; top: 0; left: 0; bottom: 0; right: 0; background: #f0f0f0; } 方法3:aspect-ratio属性 HTML结构相同。 CSS: .container { width: 100%; aspect-ratio: 16/9; position: relative; } .content { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #f0f0f0; } 注意:aspect-ratio属性在较新的浏览器中支持(Chrome 88+, Firefox 87+, Safari 15+等)。如果需要兼容旧浏览器,可以使用方法1。 另外,如果希望缩放时内容也自适应,可以在.content中使用合适的布局(如flex)并设置内部元素的自适应。 下面我们给出一个完整的示例,使用padding-top技巧(兼容性好)和aspect-ratio属性(现代浏览器)两种方式,并让用户选择。 完整代码示例(包含两种方法):</think># CSS实现Div完美缩放 我将展示几种实现div完美缩放的方法,保持宽高比并适应不同屏幕尺寸。 ## 解决方案 ### 方法1: 使用padding百分比技巧(兼容性好) 这是最常用的方法,利用padding百分比基于父元素宽度的特性。 ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Div完美缩放 - 百分比技巧</title> <style> .container { width: 80%; margin: 0 auto; max-width: 800px; } .aspect-box { position: relative; width: 100%; padding-top: 56.25%; /* 16:9宽高比 (9/16=0.5625) */ background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); border-radius: 12px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.15); } .content { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; padding: 20px; box-sizing: border-box; text-align: center; } h1 { font-size: 2.2rem; margin-bottom: 15px; text-shadow: 0 2px 4px rgba(0,0,0,0.3); } p { font-size: 1.1rem; max-width: 90%; line-height: 1.6; } .ratio-indicator { position: absolute; bottom: 15px; right: 15px; background: rgba(0,0,0,0.4); color: white; padding: 5px 10px; border-radius: 20px; font-size: 0.9rem; } </style> </head> <body> <div class="container"> <div class="aspect-box"> <div class="content"> <h1>完美缩放解决方案</h1> <p>使用padding百分比技巧实现16:9宽高比容器,无论容器宽度如何变化,高度都会自动按比例调整。</p> </div> <div class="ratio-indicator">16:9 宽高比</div> </div> </div> </body> </html> ``` ### 方法2: 使用CSS aspect-ratio属性(现代方法) CSS新增的aspect-ratio属性使宽高比控制更简单直观。 ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Div完美缩放 - aspect-ratio属性</title> <style> body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: #f5f7fa; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; } .aspect-container { width: 80%; max-width: 600px; } .responsive-box { aspect-ratio: 4/3; /* 设置4:3宽高比 */ background: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 100%); border-radius: 16px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 30px; box-sizing: border-box; color: #333; box-shadow: 0 15px 35px rgba(0,0,0,0.1); transition: all 0.3s ease; overflow: hidden; position: relative; } .responsive-box:hover { transform: translateY(-5px); box-shadow: 0 20px 40px rgba(0,0,0,0.15); } h2 { font-size: 2rem; margin-bottom: 20px; color: #d32f2f; } .features { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; margin-top: 20px; } .feature { background: rgba(255, 255, 255, 0.8); border-radius: 10px; padding: 15px; text-align: center; min-width: 120px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); } .feature h3 { margin: 0 0 10px 0; font-size: 1.1rem; } .aspect-info { position: absolute; top: 20px; right: 20px; background: rgba(0,0,0,0.7); color: white; padding: 5px 15px; border-radius: 20px; font-weight: bold; } .controls { display: flex; justify-content: center; gap: 15px; margin-top: 30px; } button { padding: 10px 20px; background: #4a69bd; color: white; border: none; border-radius: 30px; cursor: pointer; font-size: 1rem; transition: background 0.3s; } button:hover { background: #1e3799; } </style> </head> <body> <div class="aspect-container"> <div class="responsive-box"> <div class="aspect-info">4:3 宽高比</div> <h2>aspect-ratio属性</h2> <p>使用CSS aspect-ratio属性可以更简单地控制元素宽高比</p> <div class="features"> <div class="feature"> <h3>简单易用</h3> <p>一行代码实现</p> </div> <div class="feature"> <h3>响应式</h3> <p>自动适应容器</p> </div> <div class="feature"> <h3>现代浏览器</h3> <p>支持Chrome、Firefox等</p> </div> </div> <div class="controls"> <button id="ratio1">16:9</button> <button id="ratio2">1:1</button> <button id="ratio3">4:3</button> </div> </div> </div> <script> const box = document.querySelector('.responsive-box'); document.getElementById('ratio1').addEventListener('click', () => { box.style.aspectRatio = '16/9'; document.querySelector('.aspect-info').textContent = '16:9 宽高比'; }); document.getElementById('ratio2').addEventListener('click', () => { box.style.aspectRatio = '1/1'; document.querySelector('.aspect-info').textContent = '1:1 宽高比'; }); document.getElementById('ratio3').addEventListener('click', () => { box.style.aspectRatio = '4/3'; document.querySelector('.aspect-info').textContent = '4:3 宽高比'; }); </script> </body> </html> ``` ### 方法3: 使用视口单位(vw/vh) 使用视口单位根据屏幕尺寸调整元素大小。 ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Div完美缩放 - 视口单位</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%); font-family: 'Arial', sans-serif; padding: 20px; } .viewport-box { width: 80vw; /* 基于视口宽度 */ height: calc(80vw * 0.5); /* 保持2:1宽高比 */ max-width: 1000px; max-height: 500px; background: linear-gradient(45deg, #43cea2, #185a9d); border-radius: 20px; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px; color: white; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); position: relative; overflow: hidden; } .viewport-box::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: radial-gradient(circle, transparent 20%, rgba(255,255,255,0.1) 25%, transparent 30%); background-size: 20px 20px; transform: rotate(30deg); animation: animateBackground 15s linear infinite; } @keyframes animateBackground { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .content-area { position: relative; z-index: 2; text-align: center; max-width: 80%; } h2 { font-size: 2.5rem; margin-bottom: 20px; text-shadow: 0 2px 10px rgba(0,0,0,0.2); } p { font-size: 1.2rem; line-height: 1.7; margin-bottom: 30px; } .size-info { background: rgba(0,0,0,0.3); padding: 15px 30px; border-radius: 30px; font-size: 1.1rem; } .dimensions { display: flex; justify-content: center; gap: 30px; margin-top: 20px; } .dimension { background: rgba(255,255,255,0.2); padding: 15px; border-radius: 10px; min-width: 120px; } .dimension span { display: block; font-size: 0.9rem; margin-bottom: 5px; } .dimension strong { font-size: 1.4rem; } @media (max-width: 768px) { .viewport-box { width: 90vw; height: calc(90vw * 0.5); } h2 { font-size: 1.8rem; } } </style> </head> <body> <div class="viewport-box"> <div class="content-area"> <h2>视口单位缩放方案</h2> <p>使用视口单位(vw/vh)创建响应式容器,根据浏览器视口大小自动调整尺寸,保持2:1的宽高比。</p> <div class="size-info">当前容器尺寸随视口变化</div> <div class="dimensions"> <div class="dimension"> <span>宽度</span> <strong>80vw</strong> </div> <div class="dimension"> <span>高度</span> <strong>40vw</strong> </div> </div> </div> </div> </body> </html> ``` ## 方法比较 | 方法 | 优点 | 缺点 | 浏览器兼容性 | |------|------|------|--------------| | **padding百分比技巧** | 兼容性好,支持所有浏览器 | 需要绝对定位内部内容 | 所有浏览器 | | **aspect-ratio属性** | 使用简单,代码简洁 | 较新的属性,旧浏览器不支持 | Chrome 88+, Firefox 87+, Safari 15+ | | **视口单位(vw/vh)** | 直接基于视口尺寸,响应式好 | 计算高度需要依赖宽度 | 所有现代浏览器 | ## 选择建议 1. 如果需要**最大兼容性**,选择padding百分比技巧 2. 如果目标浏览器**较新**,优先使用aspect-ratio属性 3. 如果需要**基于视口尺寸**缩放,使用vw/vh单位 ## 最佳实践 ```css /* 结合多种方法实现最佳效果 */ .responsive-element { /* 现代浏览器使用aspect-ratio */ aspect-ratio: 16/9; /* 旧浏览器回退方案 */ width: 100%; position: relative; } /* 为不支持aspect-ratio的浏览器提供回退 */ @supports not (aspect-ratio: 16/9) { .responsive-element::before { content: ''; display: block; padding-top: 56.25%; /* 16:9宽高比 */ } .responsive-element > * { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } } ``` 这个组合方案首先使用现代aspect-ratio属性,并为不支持该属性的浏览器提供padding技巧的回退方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值